Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Local TimeZoneInfo

Tags:

c#

I am using C#. I need to get the local time zone info for the person running a web application.

I was wondering if:

TimeZoneInfo tzinfo = TimeZoneInfo.Local; TimeZoneInfo.ConvertTimeFromUtc(result.DueDate.Value, tzinfo); 

is appropriate. Again depending on what time zone the person running the application is, I would like that to be reflected.

like image 918
Nate Pet Avatar asked Aug 07 '13 19:08

Nate Pet


People also ask

How do I find my local time zone?

To get the current browser's time zone, you can use the getTimezoneOffset() method from the JavaScript Date object. The getTimezoneOffset() returns the time difference, in minutes, between UTC time and local time.

What is TimeZoneInfo C#?

TimeZoneInfo Class represents any time zone in the world. Instance of TimeZoneInfo class is immutable, i.e., when we instantiate it the value can't be modified. We can't create an object of TimeZoneInfo class with a new keyword. If you have ever noticed, this is sealed class and also restricts the inheritance feature.


1 Answers

yes you are right, this is what you should use. Alternative can be

TimeZone localZone = TimeZone.CurrentTimeZone; 

but the CurrentTimeZone property corresponds to the TimeZoneInfo.Local property so no difference really.

it displays the names for standard time and daylight saving time for the local time zone.

like image 86
Ehsan Avatar answered Sep 27 '22 00:09

Ehsan