在c#中获得印度标准时间(IST)? [英] Get Indian Standard Time(IST) in c#?

查看:141
本文介绍了在c#中获得印度标准时间(IST)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 DateTime.Now()函数显示系统日期时,它给了我系统的日期和时间,并且工作正常,但是当我尝试在我的服务器上运行此页面
它给了我在印度以外的服务器的DateTime但是,我想要在服务器上执行这个页面时拿起印度的时间。
我知道可以通过文化信息类...任何建议....

When i display my system date using DateTime.Now() function It gives me system date and time and works fine but when i try to run this page on my server it gives me the DateTime of Server which is outside India But i want to pick up the time of India whenever this page is executed on server. I know it is possible through Culture Info Class... Any suggestion....

推荐答案

Put:

private static TimeZoneInfo INDIAN_ZONE = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");

作为一个字段。

然后,使用:

DateTime indianTime =  TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE);

根据需要获得时间。

这篇关于在c#中获得印度标准时间(IST)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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