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)
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With