TimeZones

M

Michael

I would like to set the timezone of a thread to allow me
to calculate the UTC time for data sourced from a number
of time zones. Although this can be done in C and C++, I
annot find how to do this is C#. Can this be done ? If
so how ?

Please note setting the culture does not impact the
timezone and a culture (like en-US) may have many
timezones.
 
F

Felix Wang

Hi Michael,

Thanks for posting.

Could you elaborate a little bit more on "data sourced from a number of
time zones"? Is it string data or the timestamps on the file?

In .Net, we have a structure "System.DateTime". It contains some members
("Parse", "ToUniversalTime", "FromFileTimeUtc" etc.) that may be helpful to
you:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemDateTimeMembersTopic.asp?frame=true

In addition, there is also a class named "System.TimeZone":

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemTimeZoneClassTopic.asp?frame=true

Please check and see whether or not these help to achieve your goal.

Happy Thanksgiving!

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
B

Bruno Jouhier [MVP]

You cannot do this with the current framework, and the TimeZone API is
really poor. You cannot enumerate available timezones, you cannot even
create a timezone with a given offset. All you can do is read the machine's
timezone, as it has been configured through the control panel, and convert
DateTime to UTC and back to the local timezone.

This is really insufficient. I have posted a request to enhance the timezone
API on the Whidbey beta newsgroup, asking specifically for the following
features:

* Enumerating timezones

* Associating a timezone to the current thread, the same way you can
associate a culture to the current thread, which is exactly what you suggest
(of course you can define your own ThreadStatic variable, but it won't have
any influence on the way DateTimes are formatted and parsed, so it is of
very little help, we need a framework level variable that works like
CultureInfo.CurrentCulture).

I would really like to see this feature in the next version of the
framework, but I feel that it won't make it unless more people complain
about the weakness of the current API (usually the .NET API is richer than
the Java API, but here is is much weaker). So, if you feel that the TimeZone
API is too weak, and if you want this feature in the next version of the
Framework, raise your voice.

Bruno.
 
R

Ron McNulty

Hi Michael

Although not possible with the current API, there are several solutions for
Windows operating systems available. They all rely on the registry info for
timezones. Google on '.NET C# Timezone'.

Regards

Ron
 
R

Ron McNulty

Come on Felix, why not just reply that .NET timezone support is rudimentary?
Bruno has summarised its failings.

Regards

Ron
 
R

Ron Vecchi

Hello Bruno,

Although off topic where can I find the Whidbey Beta Group you referenced.
What is Whidbey?

I would very much like to see timezone handling in .Net also and have spent
a couple long nights tring to handle a users current time based on zone.
Specifically I was playing around with a web app that implemented satelite
assemblies with localization. The website adjusted the assembly bases on
the browser (default) or user specified setting of their culture. But when
I wanted to handle time with the users I ran into a huge mess tring to
figure it out. Especially when getting into daylight savings and other
details.

Where can I go to post this request along with yours? It would make things
much easier.
 
M

Michael

Felix,

The system "merges" data from a number of servers. The
servers are in different timezones. The data includes
datetime fields with the datetime in local format and not
stored as UTC time.


So the cultural differences can be handled be setting
"Thread.CurrentThread.CurrentCulture".

There is no timezone equivalent (I think we need
"Thread.CurrentThread.CurrentTimezone".

I can't really on a fixed offset as then daylight saving
light is not handled. The fix looks like writing a little
app to run on the soruce system and return the culture and
offset.

C and C++ offer tx handling and setting, C# should as well.

Michael.
 
B

Bruno Jouhier [MVP]

Hello Ron,

Whidbey is the code name for the next version of Visual Studio .NET. I'm
lucky enough to be enrolled in their beta program. The newsgroups are
private newsgroups reserved to beta testers. You should contact Microsoft if
you want to participate to the beta program.

Our web application has requirements similar to yours. We would like every
visitor to feel completely "at home", i.e. get a fully localized site with
messages in his language, and times formatted in his timezone. As the server
is multi-threaded, we need the ability to set a different TimeZone in every
thread.

I will repost on the Whidbey newsgroup, with a reference to this thread, to
try to catch the attention of the people who control what will go into the
next iteration of the framework.

Today, we use a workaround: we use the Java API to manipulate timezones. You
don't even need to program in J# to do it, you can do it in C# by adding a
reference to vjslib in your C# project. Then, you can use the Java TimeZone
class from the java.util namespace (note: it is buggy on NT4). This
workaround gives us access to a richer TimeZone API but is not fully
satisfactory because DateTime values are still formatted with the machine's
timezone, we have no way to set a thread-level variable that would influence
this.

Bruno.
 
B

Bruno Jouhier [MVP]

Hi Ron,

Another way is to use the java.util.TimeZone class from the J# runtime, as I
mention in another response.

Bruno.
 
B

Bruno Jouhier [MVP]

Hi Ron,
Ron McNulty said:
Hi Michael

Although not possible with the current API, there are several solutions for
Windows operating systems available. They all rely on the registry info for
timezones. Google on '.NET C# Timezone'.

Regards

Ron
 
F

Felix Wang

Hi Michael,

I have to admit that the time zone support in the current .Net Framework is
not sufficient. It is very complicated to calculate daylight saving
time/periods among different areas and the rules are subject to changes.

I think the most convenient way to solve this may be to collect the UTC
time instead of local time from the servers.

Happy Thanksgiving!

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Top