有没有一种方法来设置本地时间,这可能比服务器的时间不同,在ASP.NET应用程序MVC3? [英] Is there a way to set the local time, which may be different than the server's time, in an ASP.NET MVC3 application?

查看:105
本文介绍了有没有一种方法来设置本地时间,这可能比服务器的时间不同,在ASP.NET应用程序MVC3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC3应用程序显示当前时间在本地,但显示的时候上传到主机服务器的时间。有没有在App.config任何方式或在web.config,我可以把我的本地时间显示,一旦我的应用程序被上传到服务器?

I have an MVC3 application the displays the current time locally, but displays the servers time when uploaded to hosting. Is there any way in the app.config or the web.config that I can set my local time to display once my app is uploaded to the server?

更新:我正在寻找一种方式来做到这一点没有全球回去和改变code为每一位我引用的DateTime的时间。这似乎有点不切实际的,不能设置全局时间的应用程序。

UPDATE:I'm looking for a way to do this globally without going back and changing the code for every time I reference DateTime. It seems a little impractical to not be able to set the time for the application globally.

推荐答案

设置时区信息和转换时间。

set timezone information in the web.config and convert your time according to the web.config's timezone.

            DateTime timeUtc = DateTime.UtcNow;

            TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById(timezoneid); // timezoneid from web.config
            DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone);

cstTime是你想要的。

cstTime is what you want.

这篇关于有没有一种方法来设置本地时间,这可能比服务器的时间不同,在ASP.NET应用程序MVC3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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