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.
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
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