简体   繁体   English

如何按照用户时区更改日期和时间

[英]How to change the day and Time as per User Timezone

I do have a requirement such as say if there is 8:00 am (Fri) in Chicago so the same time would be In Singapore as 9:00 pm (Fri) as the day remains the same but if the timing in Chicago is 8:00 pm (Fri) the same timing would be in Singapore as 9:00 am (Sat). 我确实有一个要求,例如说芝加哥是否有上午8:00(星期五),因此在新加坡,下午9:00(星期五)是同一天,因为当天保持不变,但如果芝加哥的时间是8点:00 pm(周五),新加坡的时间与上午9:00(周六)相同。

The date change I am able to do by using the following function in SQL 我可以在SQL中使用以下功能来完成日期更改

dateadd(mi, 840, dateadd(hh, -1, '2015-01-30 08:00:00.000')

Where 840 is offset timing for Singapore and -1 is tzAdjust and 2015-01-30 08:00:00.000 is Datetime in Chicago But how to convert the day as above I am not getting that. 其中840是新加坡的偏移时间,而-1是tzAdjust,而2015-01-30 08:00:00.000是芝加哥的Datetime,但是如何转换上述日期,我没有得到。

Does something like this work? 这样的事情行吗?

DECLARE
     @TimeHere DATETIME2(3)
    ,@OffsetMinutes INT

SELECT
     @TimeHere = GETDATE()
    ,@OffsetMinutes = 840

SELECT
    DATEADD(MINUTE,@OffsetMinutes,@TimeHere)    AS TimeThere

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM