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

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

问题描述

我有点迷失在时区:)



我有时间以UTC存储数据。
服务器位于荷兰,所以我们生活在utc + 1(现在,在utc + 2中的daylightsavingtime)



现在客户端说:give我从8月5日的数据。



所以我必须从他的时间计算utc时间。
为此我必须知道:



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



然后我的问题:


$ b $我可以请求.Net框架:国家XX是否有日光时间?


  • 我可以问.Net框架:08-05-2010T00:00:00在那个时候的国家XXX daylightsavingtime?


  • 我一直在尝试.ToLocalTime(),但这只给了我在服务器上的本地时间,这不是我想要的,我想用用户的时区计算,还有在这个特定点的事实在时间上,如果他/她在白天休息时间



    我也看过这个VB示例:

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

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

    解决方案

    您不能询问有关特定国家的框架,但您可以询问特定的时区。



    TimeZoneInfo 考虑到DST。 (Heck,它不会有 IsDaylightSavingTime 方法否则。)如果您有两个用户,其中一个用户正在观察DST,另一个用户不是,那么他们不是相同的时区。



    如果您可以指定您正在谈论的位置,我可以尝试找出涉及哪个时区。 (通常更容易找出Olson的名称,但是找出Windows ID不是不可能的。)


    i'm a little lost in the timezone :)

    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)

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

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

    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)

    Then my questions:

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

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

    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

    I've also seen this VB example:

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

    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 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.

    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天全站免登陆