tags:

views:

1095

answers:

3

is there a format in ToString() method of DateTime to convert the time Zone to say UTC ?

I know I can programatically first convert the DateTime to UTC and then call ToString, but I have a UI where the user can specify format, can they at the same time convert to UTC ?

A: 

No, you'll first have to convert the DateTime to the desired time zone.

lush
+1  A: 

Not built in, but you can create your own formatter (google IFormatProvider)

Tim Jarvis
+2  A: 

The .ToString("u") will format as UTC but not convert. This code below will convert and present the Date and Time in UTC format:

System.TimeZone.CurrentTimeZone.ToUniversalTime(Date.Now).ToString("u")

or

DateTime.Now.ToUniversalTime().ToString("u")

other formats can be found here

John