tags:

views:

18

answers:

1

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)

+1  A: 

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.

ShinTakezou
Isn't the indian timezone +04:30 ? I guess I will have to strip the ":" from the result of zzz
citronas
it could be (it is http://www.worldtimezone.com/wtz014.php )... but zz returns only the +04. It depends on how much important is to retain the correct exact timezone. If correct precise timing is needed, strip :, otherwise an error of +/-30 minutes is acceptable
ShinTakezou