Get UTC Offset in WP7

Does anyone know a better way to get UTC offset in WP7? Apparently, TimeZone api is not implemented there.

thanks

+1
source share
4 answers

Just use DateTimeOffset.Now.Offset ... so DateTimeOffset was created!

0
source

If you just want to convert to local time, use DateTime.ToLocalTime() . If you want an offset, I think you can subtract the original value. Documentation

0
source

I recently did something like below; it was done quickly, but it works. In my case, I always wanted time from the eastern time zone, since that was where my application was. Saved as UTC and calculated offset.

  private DateTime _startTimeUtc; private DateTime _startTime; public DateTime StartTime { get { return _startTime; } set { _startTimeUtc = value.ToUniversalTime(); _startTime = _startTimeUtc.Subtract(EasternTimeUtcOffSet); } } public DateTime StartTimeUtc { get { return _startTimeUtc; } set { _startTimeUtc = value; _startTime = _startTimeUtc.Subtract(EasternTimeUtcOffSet); } } private static TimeSpan EasternTimeUtcOffSet { get { return TimeSpan.FromHours(4); } } 
0
source
  private int TimeZoneOffset() { DateTime dt = DateTime.Now; return dt.Subtract(dt.ToUniversalTime()).Hours; } 
0
source

Source: https://habr.com/ru/post/892920/


All Articles