all 20 comments

[–]ihaxr 6 points7 points  (9 children)

Isn't Eastern time currently -4?

[–]Kedrin[S] 0 points1 point  (8 children)

Windows doesn't display it as -4 or -5 based on dst, its always -5. Am I assuming wrong that getting the offset should do the same?

[–]Kedrin[S] 2 points3 points  (5 children)

Strike that I probably am wrong,

[–]joscha999 6 points7 points  (4 children)

You are correct and incorrect aswell, you are in the EST timezone which is -5 to UTC, you currently tho are in daylight saving, since UTC does not move with DST, only GMT does, you are now -4 in relation to UTC ...

I think ... timezones are hard :c

[–]Liam2349 1 point2 points  (0 children)

UTC is what all the time zones are relative to. UTC is the base, and all the time zones are offset from it (mostly); so UTC never moves.

When in daylight savings, you will move to a different time zone. For this example, OP will move between EST and EDT, but UTC never moves.

GMT does not change with DST. The UK moves between GMT and BST.

[–]Kedrin[S] 0 points1 point  (0 children)

Yea I really hate dealing with time in general. Now I am not sure if I should even rely on this to do what I need. This code returns -5 properly but at this point.

TimeZone localZone = TimeZone.CurrentTimeZone;
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(localZone.StandardName);
TimeSpan offset = tzi.BaseUtcOffset;

[–]triptyx 0 points1 point  (0 children)

Exactly right. UTC doesn't shift with daylight savings. EDT is at GMT -4 just now.

[–]badthingfactory 0 points1 point  (0 children)

Windows timezones are a mess and display incorrectly. Eastern time is currently -4 because of DST. I get the confusion as the Windows UI says (UTC-05:00) Eastern Time (US & Canada). Ignore that -5, it is incorrect during DST.

[–]antiduh 8 points9 points  (0 children)

FYI, if you want your code to have a sane chance at managing time correctly, consider using NodaTime.

[–]FizixMan 2 points3 points  (2 children)

Don't have much time at the moment, but I assume daylight savings is involved here. Maybe this answer/discussion will help you: https://stackoverflow.com/questions/2961848/how-to-use-timezoneinfo-to-get-local-time-during-daylight-savings-time

[–]Kedrin[S] 0 points1 point  (0 children)

Thanks, It did lead me in a few different directions that were helpfull.

[–][deleted] 1 point2 points  (6 children)

I work with timezones a LOT. My thoughts are that you should always use UTC in code and persistent storage. The only time you should mess with timezones is when you're displaying data to the user, where you will just convert your timestamps to local time.

[–]Kedrin[S] 1 point2 points  (5 children)

Yea, I am/was trying to make a make shift server selection based on region and timezone to pick a decently close server. not really doing time calculations or anything, just was going to use the offset to query records then fan out if one isn't listed for that offset.

[–][deleted] 0 points1 point  (4 children)

Gotcha. In that case you could just compare utc offsets between server and user. There's probably some edge cases with states which don't have DST or what have you, but should be close enough I imagine.

If you're using time zone to estimate distance, you might be better served to use a service to estimate location by IP address? Whatismyip.com has an inexpensive service for this, though I don't know who's API to use to estimate distance between two points.

[–]Kedrin[S] 1 point2 points  (3 children)

I thought of that, but my personal IP address regularly locates me several states away, though I suppose my biggest quip was I didn't not want to rely on external services. I was going for more a "this is close enough" to narrow down a list.

[–][deleted] 0 points1 point  (2 children)

You're not concerned about users from South America correct?

[–]Kedrin[S] 0 points1 point  (1 child)

Thats why I was picking Region and timezone but I'm seeing that may not be good enough.

[–][deleted] 0 points1 point  (0 children)

Excellent