将Datetime.Now转换为印度标准时间 [英] Convert Datetime.Now to Indian standard time
本文介绍了将Datetime.Now转换为印度标准时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目中,我使用DateTime.Now函数获取当前日期。但服务器在英国,所以我在美国服务器日期获得日期。有任何代码将印度标准时间设置为Global.asax,并获得印度时间调用datetime.now函数时的所有页面?
In my project i am using DateTime.Now function to get current date.But the server is in UK so i get date in US Server Date.Have any code to set Indian standard time to Global.asax , and get Indian time to all pages when call datetime.now function?
推荐答案
private static TimeZoneInfo INDIAN_ZONE = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
DateTime indianTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE);
请参阅:DateTime.UtcNow Property [ ^ ]并了解其工作原理。看看那里提到的例子。如果有任何问题,请告诉我。
See this : DateTime.UtcNow Property[^] and understand how it works. Go through the example mentioned there. Let me know if there is any difficulty.
试试这个...
public DateTime IndianStandard(DateTime currentDate)
{
TimeZoneInfo mountain = TimeZoneInfo.FindSystemTimeZoneById(印度标准时间);
DateTime utc = currentDate;
return TimeZoneInfo.ConvertTimeFromUtc(utc,mountain);
}
Try This...
public DateTime IndianStandard(DateTime currentDate)
{
TimeZoneInfo mountain = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
DateTime utc = currentDate;
return TimeZoneInfo.ConvertTimeFromUtc(utc, mountain);
}
这篇关于将Datetime.Now转换为印度标准时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文