Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set univeral timezone for entire application in winforms [closed]

How can I set Universal timezone for entire application.

So that even if the timezone is changed, the application should show time as per universal timezone.

So is it possible to set entire application timezone?

like image 430
user1331032 Avatar asked Aug 13 '13 07:08

user1331032


People also ask

What is TimeZoneInfo C#?

To display all time zones in our current system, we use TimeZoneInfo. GetSystemTimeZone() static method that returns all available time zones on a machine. The DisplayName property is the name of the time zone.


1 Answers

Unfortunately you cannot (You could look at Jon Skeet response in following thread: Setting/Changing an .NET application's TimeZone). So you have two options:

  1. Everywhwer use DateTime.ToUniversalTime (MSDN description)
  2. Create your own class which represents DateTime and use it instead
  3. You can use one more trick. You can mock DateTime with for example Microsoft Fakes. Look more here: Using shims to isolate your application from other assemblies for unit testing
like image 155
Piotr Stapp Avatar answered Nov 14 '22 22:11

Piotr Stapp