开发者

Get site region DateTime in ASP.NET

开发者 https://www.devze.com 2023-03-20 14:15 出处:网络
I need to get real DateTime by CultureInfo object. For example, my site is on US company server (that has own US time) but site is for Italy (example), where time is different, and on the site I shoul

I need to get real DateTime by CultureInfo object. For example, my site is on US company server (that has own US time) but site is for Italy (example), where time is different, and on the site I should show Italy time, not US. In web.congig I have currentCulture="it-It"

Is it possible to get time for site and if so, what is the right way to do it? Actually it would be great to have a functio开发者_Go百科n like:

public static DateTime GetSiteDate(CultureInfo ci)
{
....
return siteDate;
}

Thanks!


It is likely not possible to get the local time based on culture alone, mostly because time zones don't correspond one-to-one to countries. While Italy's time zone is Central European Standard Time (if I'm not mistaken), it will not always be the case that each country has a single time zone. For example, in the United States there are at least four time zones.


to find date DateTime.Now(); to find zone DateTime.Zone();

If you need much, there is no chance in ASP.NET you have to make use of Java Scripts to fulfill your needs.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号