如何获得本地时间在不同的时区的服务器上? [英] How to get the Local Time on a server in a different timezone?

查看:109
本文介绍了如何获得本地时间在不同的时区的服务器上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自印度,我有在美国与GoDaddy共享服务器托管的ASP.net网站。

I am from India and I have a shared server with GoDaddy in the US for hosting an ASP.net website.

当我使用 DateTime.Now 属性我得到的时间是美国。

When I Use DateTime.Now property I get the time in US.

我怎样才能将其更改为印度的时间,整个我的应用程序?

How can I change it to Indian time for whole my application?

推荐答案

使用的TimeZoneInfo 是最好的方法:

var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
var now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, timeZoneInfo);

这篇关于如何获得本地时间在不同的时区的服务器上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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