简体   繁体   中英

how to get user local machine time zone in c#

how to get user local machine time zone in c#. I'm trying to get time by using

var PublishedOn = DateTime.Now;

but time shows according to the server not local user machine.

The only place where you can get such information reliably is the client machine. Javascript would be the way to go.

Geo-location will not work when behind a proxy and is generally not very reliable (in my experience).

DateTime.Now will be the machine where the code is executed. You can use the IP of the incoming request:

Request.UserHostAddress

to get some idea of the geo location using an API like

https://freegeoip.net

TimeZone.CurrentTimeZone is used for the time zone on the computer where the code is executing. Check these links: http://msdn.microsoft.com/en-us/library/system.timezone.currenttimezone.aspx

http://msdn.microsoft.com/en-us/library/system.timezoneinfo.local.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM