如何在Asp.net获得印度的UTC时间? [英] How to get UTC time of india in Asp.net?

查看:81
本文介绍了如何在Asp.net获得印度的UTC时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站上选择Indian DateTime。在本地它正在获得正确的日期,但如果我将其上传到服务器,那么它将获得不同的日期,因为服务器在美国。因此它正在以文本形式获得USA DateTime。



这里我想在该文本框中获取Indian DateTime。那么我该如何解决这个问题呢?



我尝试了很多方法,但是我没办法。



DateTime.UtcNow.ToUniversalTime()。ToShortDateString()

DateTime.Now.ToUniversalTime()。ToShortDateString()



和其他一些方法。请帮我解决这个问题。





先谢谢

解决方案

< blockquote>放置在源页面的标题中

<%@ Page%> 

您的文化印地语(印度)hi-IN

 Culture =hi -IN


我认为你要找的是这样的。

 //使用是时候避免夏令时了。并使用正确的小时数
numberOfHoursToAdd = 7;
private DateTime today = DateTime.Now.AddHours(numberOfHoursToAdd);





希望这会有所帮助。



编辑固定拼写错误。


试试这个。





 TimeZoneInfo timzoe = TimeZoneInfo.FindSystemTimeZoneById(  India Standard Time );然后

DateTime indiaTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow,timzoe);


I want to pick Indian DateTime in my website. Locally it's getting correct date, But if I upload it to Server then it is getting different date, Because Server is in USA. So it is getting USA DateTime in text.

Here I want to get Indian DateTime in that textbox. So How Can I fix this problem?

I tried many ways but i din't get.

DateTime.UtcNow.ToUniversalTime().ToShortDateString()
DateTime.Now.ToUniversalTime().ToShortDateString()

and some other ways. Please help me to solve this problem.


Thanks in Advance

解决方案

Place in the header of your source page

<%@ Page %>

your culture Hindi (India) hi-IN

Culture="hi-IN"


I think what you are looking for is something like this.

//use utc time to avoid daylight savings time in us. and use correct number of hours
numberOfHoursToAdd = 7;
private DateTime today = DateTime.Now.AddHours(numberOfHoursToAdd);



Hope this helps.

Edit fixed typo.


try this.


TimeZoneInfo timzoe = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"); and then 

DateTime indiaTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow,timzoe);


这篇关于如何在Asp.net获得印度的UTC时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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