-1
DateTime localDate = DateTime.Now;
DateTime dt = new DateTime(localDate.Year, localDate.Month,
                           DateTime.DaysInMonth(localDate.Year, localDate.Month),
                           localDate.Hour, localDate.Minute, localDate.Second);

dt value is 31-08-2013 PM 06:45:00

Because my system date format is in PM 06:45 30-08-2013.

I would like to get the value as 08-31-2013 18:45:00 in a variable of type DateTime not of string type.

Filburt
  • 17,626
  • 12
  • 64
  • 115
RajVish
  • 191
  • 2
  • 13
  • 1
    Possible duplicate http://stackoverflow.com/questions/5590180/how-to-convert-a-datetime-string-to-a-current-culture-datetime-string http://stackoverflow.com/questions/13797727/datetime-and-cultureinfo http://stackoverflow.com/questions/4353232/how-can-i-get-date-and-time-formats-based-on-culture-info – Josh C. Aug 30 '13 at 13:26
  • I think you just have a formatting problem here. See the various formatting options for .ToString() with the DateTime type. See here: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx – Marcel Aug 30 '13 at 13:26
  • 1
    The value of a `DateTime` object is neither `31-08-2013 PM 06:45:00` nor `08-31-2013 18:45:00`, nor any other human-readable format. Internally the date is stored as a single long integer which represents the number of ticks since January 1st of the year 1. Any time you're looking at it as a date string it's because it's been converted to a string, for instance if you're looking at its value in the debugger. – Magnus Grindal Bakken Aug 30 '13 at 13:30

1 Answers1

2

The date/time is stored in a particular format regardless of the system locality. Only the the output is affected by the locality.

Regardless of how it "looks" you can always change the output using the ToString method

And the various formats

You can even implement a global cultureinfo to apply which may be what you're looking for

Shawn E
  • 472
  • 2
  • 8