开发者

TimeZoneInfo Class and Daylight saving time

开发者 https://www.devze.com 2023-03-27 03:25 出处:网络
I am trying to get the Timezone of the device (windows phone). I used this class and the property BaseUtcOffset. I live In Jordan, and it was suppose to give me +3 hours, but instead it gave me +2. i

I am trying to get the Timezone of the device (windows phone). I used this class and the property BaseUtcOffset. I live In Jordan, and it was suppose to give me +3 hours, but instead it gave me +2. i th开发者_高级运维ink its the daylight saving time, but i have no idea how to use it, any ideas?

var x = TimeZoneInfo.Local.BaseUtcOffset;  // x.Hours = 2

the correct timezone from timeanddate.com


You should use GetUtcOffset().

The BaseUtcOffset property returns the difference between UTC and the time zone's standard time; the GetUtcOffset method returns the difference between UTC and the time zone's time at a particular point in time.


That's the right response. The timezone is 2 hours ahead of UTC. Local time is 3 hours ahead of UTC.

You might want to look at GetUtcOffset() or IsDaylightSavingsTime().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号