如何将UTC日期转换为本地时间 [英] How to convert UTC Date to Local Time

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

问题描述

Hello Guys,



在我需要将用户检索数据并呈现的数据库中存储的UTC DateTime转换为本地时间的情况下,我很笨在他们各自的浏览器中。



我当前的解决方案是:获取当前用户的时区并存储在会话中并使用它进行转换utc到当地时间。



当前问题:当前用户的时区可能因夏令时而异。对于当前用户的时区处于夏令时模式但转换日期是常规时间的场景。



场景:

1.用户在常规时间保存数据

2.在夏令时期间用户打开应用程序并检索数据

3.转换日期时间将使用的时区是夏令时



问题:

1.什么是最好的方法处理从utc到当地时间的日期时间转换还会考虑夏令时吗?

2.有没有办法确定utc是在白天还是普通时间?

Hello Guys,

I am stumble in the scenario where i need to convert UTC DateTime stored in the database to local time once the user retrieved the data and rendered in their respective browsers.

My current solution is: to get the timezone of the current user and store in session and use that to convert the utc to local time.

current problem: the timezone of the current user might vary for daylight saving. and for scenario where the timezone of the current user is in daylight saving mode but the date to convert is in regular time.

scenario:
1. user saved data on regular time
2. during daylight saving user open the app and retrieved data
3. when converting the datetime the timezone that will be use is daylight saving

Question:
1. What is the best approach to handle datetime conversion from utc to local time where daylight saving is also considered?
2. Is there a way to determine if the utc is in daylight or ordinary time?

推荐答案

请参阅 http://www.w3schools.com/jsref/jsref_gettimezoneoffset.asp [ ^ ]。


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

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