时区 [英] TimeZones

查看:72
本文介绍了时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一个线程的时区允许我

来计算来自数字时间区域的数据的UTC时间。虽然这可以在C和C ++中完成,但我不知道如何做到这一点就是C#。可以这样做吗?如果

怎么样?


请注意设置文化不会影响

时区和文化(如en-US )可能有很多

时区。

解决方案

嗨迈克尔,


感谢您发帖。


您能否详细说明来自多个

时区的数据?它是字符串数据还是文件上的时间戳?

在.Net中,我们有一个结构System.DateTime。它包含一些成员

(Parse,ToUniversalTime,FromFileTimeUtc等),可能对你有帮助。

你:

http ://msdn.microsoft.com/library/de...us/cpref/html/

frlrfSystemDateTimeMembersTopic.asp?frame = true


此外,还有一个名为System.TimeZone的类:

http://msdn.microsoft.com/library/de...us/cpref/html/

frlrfSystemTimeZoneClassTopic.asp?frame = true


请检查一下这些是否有助于实现目标。


感恩节快乐!


问候,


Felix Wang

Microsoft在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有授予任何权利。


你不能用当前的框架做到这一点,而且TimeZone API真的是

较差的。你不能枚举可用的时区,你甚至不能创建一个给定偏移量的时区。您所能做的就是阅读机器的

时区,因为它是通过控制面板配置的,并将

DateTime转换为UTC并返回到本地时区。


这真的不够用。我已经在Whidbey beta新闻组上发布了一个增强时区

API的请求,专门询问以下

功能:


*枚举时区


*将时区与当前线程相关联,就像你可以将
将文化与当前线程关联一样,这正是你建议

(当然你可以定义你自己的ThreadStatic变量,但它不会对DateTimes格式化和解析的方式产生任何影响,所以它是

很少帮助,我们需要一个框架级变量,就像

CultureInfo.CurrentCulture)。


我真的会喜欢在

框架的下一个版本中看到这个功能,但我觉得除非有更多的人抱怨当前的弱点,否则它不会成功API(通常.NET API比Java API更丰富,但是这里要弱得多)。所以,如果你觉得TimeZone

API太弱了,如果你想在下一个版本的

框架中使用这个功能,请提高你的声音。


Bruno。


" Michael" < MI ******* @ avanade.com> aécritdansle message de

news:7c **************************** @ phx.gbl。 ..

我想设置一个线程的时区,以便我能够计算来自多个时区的数据的UTC时间。虽然这可以在C和C ++中完成,但我不知道如何做到这一点就是C#。可以这样做吗?如果
如此?

请注意,设置文化不会影响
时区,文化(如en-US)可能有很多
时区。



嗨迈克尔


虽然目前的API无法实现,但有几种解决方案可用于
Windows操作系统可用。他们都依赖于

时区的注册表信息。谷歌在''.NET C#时区''。


问候


Ron


" ;迈克尔" < MI ******* @ avanade.com>在消息中写道

news:7c **************************** @ phx.gbl ... < blockquote class =post_quotes>我想设置一个线程的时区,允许我
计算来自多个时区的数据的UTC时间。虽然这可以在C和C ++中完成,但我不知道如何做到这一点就是C#。可以这样做吗?如果
如此?

请注意,设置文化不会影响
时区,文化(如en-US)可能有很多
时区。



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.

解决方案

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/de...us/cpref/html/
frlrfSystemDateTimeMembersTopic.asp?frame=true

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

http://msdn.microsoft.com/library/de...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.


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.

"Michael" <mi*******@avanade.com> a écrit dans le message de
news:7c****************************@phx.gbl...

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.



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

"Michael" <mi*******@avanade.com> wrote in message
news:7c****************************@phx.gbl...

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.



这篇关于时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆