-1

Hi have been dealing and searching information in several forums but cannot resolve my problem. I'm working on a task that needs to be executed at 2 pm Central Time, what I want to do is to get the time zone of the server and convert it from 2 pm Central Time to the server time. For example if server time is on EST the time would be 3 pm, if server time is on PST time would be 12 pm and so on any guidance would be appreciate it.

Thanks

  • I believe that [this](https://stackoverflow.com/questions/319367/how-to-convert-server-time-to-local-time) question answers yours as well? – Vandenberghe Willy Apr 30 '18 at 08:08
  • See the duplicate answer. In your case, Eastern Time (the time of the server) is not relevant. Simply convert from `DateTime.UtcNow` to `"Central Standard Time"` (which is inclusive of both CST and CDT despite the name), using the `TimeZoneInfo.ConvertTimeFromUtc` method, as shown in the dup. – Matt Johnson-Pint Apr 30 '18 at 17:34

1 Answers1

0

Generally, servers are set to run in UTC, which means you only have to do one conversion to (or from) the users timezone in the UI layer. If your servers really are set to a non-UTC timezone, you would need to convert to UTC and back (just to make the conversion easiest, not simplest). Also, watch out for DST issues.

here is an official page about converting between time zones: https://learn.microsoft.com/en-us/dotnet/standard/datetime/converting-between-time-zones

TimeZoneInfo easternZone =   
 TimeZoneInfo.FindSystemTimeZoneById(easternZoneId);
Console.WriteLine("The date and time are {0} UTC.",                  
    TimeZoneInfo.ConvertTimeToUtc(easternTime, easternZone));
Neil
  • 11,059
  • 3
  • 31
  • 56