Reputation: 19355
I have a DateTime object. I want to return a String formatted as this one below:
Thu, 06 June 2010 16:00:00 +0200
This is my code so far:
DateTime.Now.ToString("ddd, dd MMMM yyyy HH:mm:ss zzz");
Result:
Thu, 10 Juni 2010 18:33:14 +02:00
Is there a built-in way to get the timezone difference formatted without : ? (without manually stripping the :. Don't know if there are any complications, if I do so)
Upvotes: 5
Views: 5230
Reputation: 1597
Note you can use "o" to have a full datetime with time zone. It can be usefull for log stuff.
DateTime.Now.ToString("o") => 2012-08-17T17:31:19.7538909+08:00
Upvotes: 3
Reputation: 9661
It seems (I've searched), there's no way apart manipulating the resulting string. If you use zz
you get only "+02" however... then you could append 00, instead of "searching"(regex or whatever) for the last : and strip it. DateTimeFormatInfo
allows to know the separator for h:m:s, d/m/y, but not timezone; moreover if DateTimeFormatInfo.TimeSeparator affects timezone too (being h:m), you can't search for : snce it could not work on all locales, you should search for DateTimeFormatInfo.TimeSeparator instead; or zz and append 00 at the end... For now, it is all about my ideas to help you.
Upvotes: 2