如何在全球范围内将UTC日期时间转换为用户指定的本地日期时间 [英] how to Globally convert UTC DateTimes to user specified local DateTimes

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

问题描述

我想将UTC日期时间转换为本地所以任何在ecan操作应用程序然后它将需要他们的当地时间,但它应该是全局的,不必在所有页面中插入

i want to convert UTC date time to local so any on ecan operate app then it will take their local time but it should be global dont have to cange in all pages

推荐答案

DateTime 类本身中有这样做的方法,请参阅下一个示例:

There is method for doing this in DateTime class itself, see the next example:
DateTime utcDate1 = date1.ToUniversalTime(); //This is an UTC date!
DateTime date2 = utcDate1.ToLocalTime(); // And now is converted to local date!





此解决方案适用于Windows桌面应用程序,但不适用于Web应用程序,因为客户端可能来自任何国家/地区,并且您的代码在服务器上运行。所以在第二种情况下你应该看到下一个链接,你必须在你的网页中使用Javascript:

http://www.w3schools.com/jsref/jsref_gettimezoneoffset.asp [ ^ ]


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

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