I am looking for a way to determine the UTC Timezone Offset (eg. -7:00) given the local computer settings. FDateTime accounts for daylight savings so it does not give me the correct answer to find the timespan from LocalTime to UTCTime (eg. will give -6). How can I determine whether daylight savings is on?
Hi , @jo.codegirl, you can get the computer’s datetime with FDateTime:Now(). Also, if you want to have the difference between your pc’s time and the utcDatetime you can do this
int utcnow = FDateTime::UtcNow().GetHour();
int now = FDateTime::Now().GetHour();
int diff = now - utcnow;
and get the difference in hours. Remember use #include “Misc/DateTime.h”
2 Likes
Hi, We’ve encountered this issue too, and @ariveros327 's answer provided us with a good idea.
But we have to point out that there’s a bug:
If it’s 2:00 AM +8, the diff calculated from the method suggested above would give a wrong answer of -16 due to the fact that Utc time is still in the previous day. The better way for doing this is
auto diff = FDateTime::Now() - FDateTime::UtcNow();
auto hourDiff = diff.GetHours();
1 Like
Just for your information, there are UTC offsets such as UTC+09:30.
Wikipedia: Time zone