Converting .NET 2.0 DateTime.ToString () to a different timezone

Is there a format in the ToString () DateTime method to convert the timezone to say UTC?

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

0


a source to share


3 answers


.ToString ("u") will be formatted as UTC, but not converted. This code below converts and represents 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

+4


a source


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



+1


a source


No, you first need to convert the DateTime to your required timezone.

0


a source







All Articles