Localization of Date Time
The DateTime ToString() method serializes a date using the current locale. The "u" format string uses a universal pattern displaying the date from most general to most specific. The "o" format string includes time zone information binding the time to a specific zone.
Example Code
' create an invariant date string
Dim lvDate1 = New DateTime(Now.Year, 6, 13, 13, 1, 1, DateTimeKind.Local)
Dim lvDateStr1 = lvDate1.ToString("u") ' 2009-06-13 13:01:01Z
Dim lvDateStr2 = lvDate1.ToString("o") ' 2009-06-13T13:01:01.0000000-04:00
Dim lvDate3 = DateTime.ParseExact(lvDateStr1, "u", Globalization.CultureInfo.InvariantCulture)
Dim lvDate4 = DateTime.ParseExact(lvDateStr2, "o", Globalization.CultureInfo.InvariantCulture)
References
DateTime Format Strings - http://msdn.microsoft.com/en-us/library/97x6twsz.aspx
DateTimeFormatInfo - http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo_properties.aspx
Comments (0)
You don't have permission to comment on this page.