Timezone info in CODESYS

Good afternoon

I’m not getting the expected results from the SysTimeRtcGetTimezone call. The controller time configuration is:

cs_sys

While the call to to SysTimeRtcGetTimezone returns:

cs_utc

If that’s the expected result, how do I go about getting the current time of the controller?

Thanks
Vic

Use the SysTime library instead. You can get the “Date and Time” example from our store and look at the “SystemTimePrg” program to learn how to get time and do conversions.

See the below examples for using date and time in codesys.
https://store.codesys.com/date-and-time.html

Here is some sample code:
// Get UTC time in milliseconds since Thursday, 1.1.1970 00:00:00
Result := SysTimeRtcHighResGet(stUTC_Timestamp); // ULINT#1528273494913
// Convert UTC time to local timezone.
Result := SysTimeRtcConvertHighResToLocal(stUTC_Timestamp, stdNow);

// stdNow.wYear = UINT#2018
// stdNow.wMonth = UINT#6
// stdNowy.wDay = UINT#6
// stdNow.wHour = UINT#10
// stdNow.wMinute = UINT#24
// stdNow.wSecond = UINT#54
// stdNow.wMilliseconds = UINT#913
// stdNow.wDayOfWeek = UINT#3
// stdNow.wYday = UINT#157

Result := SysTimeRtcConvertDateToHighRes(stdNow, stLocal_TimeStamp); // ULINT#1528280694913

dtNow := TO_DT(stLocal_TimeStamp / 1000 (* ms *)); // DT#2018-6-6-10:24:54
todNow := TO_TOD(stLocal_TimeStamp MOD TO_ULINT(T#1D)); // TOD#10:24:54.913
datToday := TO_DATE(dtNow); // D#2018-6-6

and a screenshot of what it looks like running:

1 Like

I can’t remember specifically, but I believe that I based my code on that exact sample. I’m using the high res version because the SysTimeRtcConvertUtcToLocal is marked as deprecated.

But none the less, is the screenshot above on your system or from the examples? This is what I get on my system:

Note that the RTC time in UTC and RTC time in local time are the same value.

That’s why I was asking about the time zone stuff. The time that I get is ahead by exactly 5 hours. Which, if I’m not mistaken, is the difference between UTC and CDT.

The screenshot above is what the running date time logic looks like on my EPIC at my desk. It shows the correct time.

The code snippet above is showing the HighRes command, and here it is it executed, it returns the current time on my EPIC, and not UTC.

You can see UTC and local timestamps are different.

Good morning

This is on my system. The screen shot was taken at July 8th 0911 CDT. Notice that the time is ahead by 5 hours.

What could be causing this discrepancy?