timezone / culture weirdness

C

Chris Porter

Just as I thought I was understanding doing timezone offsets I ran the
following code :

CultureInfo en = new CultureInfo("en-GB");
Thread.CurrentThread.CurrentCulture = en;
Response.Write(String.Format("culture {0}<br />",
Thread.CurrentThread.CurrentCulture.ToString()));

DateTime dt = new DateTime(2003, 11, 22, 1, 0, 0);

DateTime utcdt = dt.ToUniversalTime();

// Defines a custom string format to display the DateTime value.
// zzzz specifies the full time zone offset.
String format = "dd/MM/yyyy hh:mm:sszzz";

String str = dt.ToString(format);
Response.Write(String.Format("str: {0}<br />", str));

String utcstr = utcdt.ToString(format);
Response.Write(String.Format("utcstr: {0}", utcstr));

On my uk workstation this is the output :

culture en-GB
str: 22/11/2003 01:00:00-00:00
utcstr: 22/11/2003 01:00:00-00:00

On the server in the USA this is the output :

culture en-GB
str: 22/11/2003 01:00:00-08:00
utcstr: 22/11/2003 09:00:00-08:00

So why is the USA server showing the 8 hour timezone offset and messing up
my datetime calculations despite both showing a culture en-GB ????

Thanks in advance. :)
 
B

Bret Mulvey [MS]

Chris Porter said:
Just as I thought I was understanding doing timezone offsets I ran the
following code :

<snip>

On my uk workstation this is the output :

culture en-GB
str: 22/11/2003 01:00:00-00:00
utcstr: 22/11/2003 01:00:00-00:00

On the server in the USA this is the output :

culture en-GB
str: 22/11/2003 01:00:00-08:00
utcstr: 22/11/2003 09:00:00-08:00

So why is the USA server showing the 8 hour timezone offset and messing up
my datetime calculations despite both showing a culture en-GB ????

DateTime.ToUniversalTime() uses the value of TimeZone.CurrentTimeZone to
determine the UTC offset. The value of TimeZone.CurrentTimeZone comes from
the system, not from the thread culture.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top