Possible Duplicate:
datetime to string with time zone
This is one of the W3C standard date time format that I want to use in sitemap. This DateTime standard is:
Complete date plus hours, minutes and seconds:
YYYY-MM-DDThh:mm:ssTZD where TZD = time zone designator (Z or +hh:mm or -hh:mm) (eg 1997-07-16T19:20:30+01:00)
I am using the following code to get the current DateTime in that format:
DateTime.Now.ToString("yyyy-MM-ddThh:mm:ssTZD");
But this gives: 2011-08-10T02:27:20TZD
Apparently the DateTime.Now doesn’t recognize “TZD” in the parameter. Please help. How can I get the current DateTime in this format?
Use the
zzzformat specifier to get the timezone offset as hours and minutes. You also want to use theHHformat specifier to get the hours in 24 hour format.Result:
Some culture settings uses periods instead of colons for time, so you might want to use literal colons instead of time separators:
Custom Date and Time Format Strings