locked
System DateTime format problem in C#. RRS feed

  • Question

  • Hi....

    In my program, It stores a lot of dates in list<string> in dd/MM/yyyy format( in string format). And I have to convert it to list<DateTime>. But the problem is, I want the corresponding list <DateTime> in the format that is specified in the Control pannel ->Date,Time,Language, and Regional Options.

    Is there any method in C#  to get the system datetime format ?  plz help

    Monday, July 19, 2010 8:40 AM

Answers

  • string strdate = "01/05/2010";
    string dt = DateTime.ParseExact(strdate, "dd/MM/yyyy", DateTimeFormatInfo.InvariantInfo).ToString("MM/dd/yyyy");
    Manish Sati
    • Marked as answer by bvtom Tuesday, July 20, 2010 12:32 PM
    Tuesday, July 20, 2010 5:43 AM

All replies

  • Hello,

     

    Let me ask--   could you say more about what you are looking for regarding "Language" and "Regional options" ?

     

    Is there some constant data describing Language & Regional Options that you are trying to store with each DateTime?

    Or are you trying to report/display each DateTime with different formatting for different users, depending on the user's Language and Regional Options?

    Monday, July 19, 2010 3:45 PM
  • Could you paste an example of what you want displayed?
    Monday, July 19, 2010 8:04 PM
  • Hi....

    I m sorry that you don't understand my question.

    my question is simple.

    Suppose if my system's short date format is MM/dd/yyyy.

    And in a list I have my dates in dd/MM/yyyy format.

    Now in my program I have to change my string dates to  systems short date format for further processing   (i.e, dd/MM/yyyy to  MM/dd/yyyy in this case).

    Also there are a number of other system short date formats.

    How to get the current short date format selected by the user? 

    Tuesday, July 20, 2010 5:08 AM
  • string strdate = "01/05/2010";
    string dt = DateTime.ParseExact(strdate, "dd/MM/yyyy", DateTimeFormatInfo.InvariantInfo).ToString("MM/dd/yyyy");
    Manish Sati
    • Marked as answer by bvtom Tuesday, July 20, 2010 12:32 PM
    Tuesday, July 20, 2010 5:43 AM
  • Hello Mr Manish Sati,

    It is really a nice piece of code. Actually I was looking for that. 

    string strdate = "01/05/2010";

    string dt = DateTime.ParseExact(strdate, "dd/MM/yyyy", DateTimeFormatInfo.InvariantInfo).ToString();

    this worked for me

    Thanks a lot...


    Tuesday, July 20, 2010 12:57 PM