How can I get Daylight Savings / UTC Timezone Offset of player's computer?

Hi!

I’m using Unreal 5 and I’m trying to get Daylight Savings / UTC Timezone Offset of player’s computer, but I don’t know how to do it.

I’ve been checking FDateTime, but I don’t think I can get Daylight Savings / UTC Timezone Offset using it.

Maybe, I have to use some Windows API.

Thanks!

You need to use the UTC now node:
image

No. That doesn’t work.

First, this is a C++ question, not a blueprint question.

Second, the UTCNow method returns the UTC time, not the Daylight Savings.

My bad, I often don’t read tags, and I completely missed FDateTime.



Here is a post:

Thanks!

I read it before asking this question. That question doesn’t talk about Daylight Savings.

Thanks.

Do a simple subtraction such as (local_time - UTC_time) and u’ll get the exact offset from UTC, meaning your local timezone. I needed the same thing and realized how to do it just now in BP, but it’ll work the same in C++.

If you are looking for UTC offset, then Pixel’s Laboratory’s suggestion works well I think!

However if you are looking to see if the current time zone is on daylight saving time at the time of execution, and if you don’t mind using c++20 in your project (and using some std::strings), perhaps you may have some luck with the sys_info struct from the chrono library.

The following prints out “60min” on my system

#include <chrono>
#include <iostream>

using namespace std::chrono;

int main()
{
    sys_time<system_clock::duration> st = system_clock::now();

    const auto& timeZoneDatabase = get_tzdb();
    const auto& currentZone = timeZoneDatabase.current_zone();
    auto sysInfo = currentZone->get_info(st);

    std::cout << sysInfo.save;

    return 0;
}

Note that it returns an std::string. Example taken from here.

1 Like