locked
how can i get a datatime in following formate(urgent) RRS feed

  • Question

  • hello
                  how can i get a datatime in following formate

    2009-12-09 17:06:36


    It's Me
    Thursday, December 10, 2009 5:33 AM

Answers

  • You can use this format:

    string format = "yyyy-MM-dd HH:mm:ss";
    Console.WriteLine(DateTime.Now.ToString(format));
    Console.WriteLine(DateTime.Parse("12/10/2009 5:06:13 PM").ToString(format));

    For other options take a look at the Date and Time Format Strings reference.

    Document my code? Why do you think it's called "code"?
    • Marked as answer by Bin-ze Zhao Tuesday, December 15, 2009 5:18 AM
    Thursday, December 10, 2009 6:23 AM
  • MessageBox

     

    .Show(DateTime.Now.ToString("yyyy-mm-dd HH:MM:ss"));

    • Marked as answer by Bin-ze Zhao Tuesday, December 15, 2009 5:18 AM
    Thursday, December 10, 2009 6:19 AM

All replies

  • MessageBox

     

    .Show(DateTime.Now.ToString("yyyy-mm-dd HH:MM:ss"));

    • Marked as answer by Bin-ze Zhao Tuesday, December 15, 2009 5:18 AM
    Thursday, December 10, 2009 6:19 AM
  • You can use this format:

    string format = "yyyy-MM-dd HH:mm:ss";
    Console.WriteLine(DateTime.Now.ToString(format));
    Console.WriteLine(DateTime.Parse("12/10/2009 5:06:13 PM").ToString(format));

    For other options take a look at the Date and Time Format Strings reference.

    Document my code? Why do you think it's called "code"?
    • Marked as answer by Bin-ze Zhao Tuesday, December 15, 2009 5:18 AM
    Thursday, December 10, 2009 6:23 AM
  • hi,

    http://www.codeguru.com/csharp/csharp/cs_date_time/formatting/article.php/c4205/
    Nagarjuna Dilip
    Thursday, December 10, 2009 9:01 AM