转换某人的本地时间与UTC时间 [英] Convert somebody's local time to the UTC time

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

问题描述

我有点在时区失去了:)

i'm a little lost in the timezone :)

我有存储在UTC时间数据。 服务器是在荷兰,所以我们生活在UTC + 1(现在,随着daylightsavingtime,在UTC + 2)

I have data stored with the time in UTC. The server is in the Netherlands, so we live in utc+1 (now, with daylightsavingtime, in utc + 2)

现在一个客户说:从8月5日给我的数据

Now a client says: give me the data from august 5th.

所以,我必须来计算他的时间UTC时间。 为此,我必须要知道:

So i have to calculate the utc time from 'his time'. For that i have to know:

什么是你的UTC偏移(我们保存在他的个人资料,让我们说UTC -6) 你在daylightsavingtime(因为那时我们必须添加+1,使UTC偏移-5)

what is your utc offset (we stored that in his profile, let's say utc -6) are you in daylightsavingtime (because then we have to add +1 and make the utc offset -5)

然后我的问题:

  1. 我可以问.net框架:是否国家XX有daylightsavingtime

  1. Can i ask the .Net framework: does country XX have daylightsavingtime?

我可以问.net框架:是08-05-2010T00:00:00在全国XXX daylightsavingtime在那一刻

Can i ask the .Net framework: is 08-05-2010T00:00:00 in country XXX daylightsavingtime at that moment?

我一直在努力的.ToLocalTime(),但这只是给了我在服务器本地时间,而这不是我想要的,我想要计算与用户的时区,也与事实在那个时间特定点,如果他/她是在daylightsavingtime

i've been trying the .ToLocalTime(), but this only gives me the local time at the server, and that's not what i want, i want to calculate with the timezone of the user, and also with the fact that at that particular point in time, if he/she is in daylightsavingtime

我也看到了这个VB例如:

I've also seen this VB example:

TimeZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time") 
Dim Dated As DateTime = TimeZoneInfo.ConvertTimeToUtc(TempDate, TimeZone) 

但IMHO这并没有考虑到,在该时区的用户是或不是在一个daylightsavingtime(dst)的国家。 例如,在这个时区一个用户是在具有dst的荷兰,和另一是在其中没有dst的另一个国家。

but imho this doesn't take into account that the user in this timezone is or is not in a daylightsavingtime (dst) country. For instance, one user in this timezone is in the netherlands having dst, and one other is in another country which has no dst.

推荐答案

您不能要求框架有关特定的国家的 - 但你可以问一个特定的时区

You can't ask the framework about a particular country - but you can ask about a particular time zone.

的TimeZoneInfo 没有的考虑DST考虑。 (哎呀,那就不会有 IsDaylightSavingTime 的方法,否则。)如果你有两个用户,其中一人正在观察DST和其他的人是不是,那么他们的没有的中同一时区。

TimeZoneInfo does take DST into account. (Heck, it wouldn't have the IsDaylightSavingTime method otherwise.) If you've got two users, one of whom is currently observing DST and the other of whom isn't, then they aren't in the same time zone.

如果你可以指定哪些位置,你在说什么,我可以尝试找出区域涉及到哪些时间。 (这是通常更容易找出奥尔森的名字,但它不应该是不可能找出的Windows标识。)

If you could specify which locations you're talking about, I could try to find out which time zones are involved. (It's generally easier to find out the Olson names, but it shouldn't be impossible to find out the Windows IDs.)

这篇关于转换某人的本地时间与UTC时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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