我有在美国服务器托管的网站。当我将数据存储在数据库中时。需要美国服务器日期/时间。那么,我如何从服务器获得印度日期/时间。我不想要本地PC时间。 [英] I have Website which is hosted in US server. when i store the data in database. it takes US server date/time. So, How can i get indian date/time from server. I dot't want local PC time.
本文介绍了我有在美国服务器托管的网站。当我将数据存储在数据库中时。需要美国服务器日期/时间。那么,我如何从服务器获得印度日期/时间。我不想要本地PC时间。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Label2.Text = DateTime.Now.ToString();
i使用此代码获取服务器时间
现在我想要印度时间..没有使用客户端PC时间..
i希望直接通过代码..
Label2.Text = DateTime.Now.ToString();
i am using this code to get server time
now i want indian time.. without using client pc time..
i want direct by code..
推荐答案
private static TimeZoneInfo INDIAN_ZONE = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
DateTime indianTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE);
只需在ToString中应用culture,如下所示< br $>
Simply apply culture in the ToString as shown below
DateTime.Now.ToString(CultureInfo.CreateSpecificCulture("hi-IN"))
应该这样做诀窍
希望有帮助
That should do the trick
Hope that helps
Label2.Text = DateTime.UtcNow.ToString();
DateTime.UtcNow Property 获取一个DateTime对象,该对象在此计算机上设置为当前日期和时间,表示为协调世界时(UTC)。
DateTime.UtcNow Property gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).
这篇关于我有在美国服务器托管的网站。当我将数据存储在数据库中时。需要美国服务器日期/时间。那么,我如何从服务器获得印度日期/时间。我不想要本地PC时间。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文