如何更改时区,一个asp.net应用程序 [英] How to change time zone for an asp.net application

查看:94
本文介绍了如何更改时区,一个asp.net应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要设置默认的时区为我的ASP.NET亚洲/达卡或GMT + 6时区。但我无法找到一个方法来全局更改它。有很多的#2的参考和休息网络通过获取时区信息,计算正确的时间,每次我需要一个DateTime对象这样做的。

I need to set default timezone for my ASP.NET to Asia/Dhaka or GMT+6 timezone. But i cannot find a way to change it globally. There is a lot of reference on Stackoverflow and rest of the web for doing this by getting timezone info and calculating correct time for each time i need a DateTime object.

但是请相信我,我并不想这样做,在这种方式。所以不给我这样的建议。我想从web.config中设置时区亚洲/达卡或GMT + 6 preferably。 (类似我们在php.ini中的PHP),这样每次我需要DateTime对象的时间与我的时区计算无论时区为什么服务器。

But trust me, I don't want to do this in this way. So dont give me any suggestion like that. I want to set the timezone to Asia/Dhaka or GMT+6 preferably from web.config. (Similar we do in php with php.ini) So that each time i need DateTime object the time is evaluated with my timezone no matter what the timezone is for server.

这可能吗?如果可能的话又如何?
预先感谢解决方案:)

Is this possible? If possible then how?? Thanks in advance for the solution :)

推荐答案

对不起没有在.NET没有办法全局更改时区。

Sorry there is no way in .NET to change the time zone globally.

你的唯一方法是改变你的服务器的时区或重写所有code的。

The only way you have is to change the timezone of your server or rewrite all of your code.

最好的做法是在所有不依赖系统时区(从不使用DateTime.Now)。

The best practice is to not rely on the system time zone at all (never use DateTime.Now).

您应该处理所有日期UTC日期,然后将它们显示给用户时转换为特定的区域。

You should handle all date as Utc dates and then convert to a specific zone when displaying them to users.

这篇关于如何更改时区,一个asp.net应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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