I might have gone a bit overboard with this, but since i wanted to use an NTP-server, but also display the time in the HMI according to the the correct timezone and also adjust based on daylight savings time this was the outcome.
The code is specific for Sweden but could probably be adjusted pretty easily…
‘’'TodayDate := CONCAT_LDATE(RTC.YEAR,RTC.MONTH,RTC.DAY);
TodayDate2 := CONCAT_LDT(RTC.YEAR,RTC.MONTH,RTC.DAY,RTC.HOURS,RTC.MINUTES,RTC.SECONDS,0,0,0);
CurrentTime := CONCAT_LTOD(RTC.HOURS,RTC.MINUTES,RTC.SECONDS,0,0,0);
Year := TO_STRING(TodayDate,‘{0:yyyy}’);
Month := TO_STRING(TodayDate,‘{0:MM}’);
Day := TO_STRING(TodayDate,‘{0:dd}’);
Hours := TO_STRING(CurrentTime,‘{0:HH}’);
Minutes := TO_STRING(CurrentTime,‘{0:mm}’);
Seconds := TO_STRING(CurrentTime,‘{0:ss}’);
UtcHours := TO_INT(Hours);
UtcYear := TO_INT(Year);
LastDayMarch := CONCAT_LDT(UtcYear,3,31,23,59,59,00,00,00);
LastDayOctober := CONCAT_LDT(UtcYear,10,31,23,59,59,00,00,00);
DayOfWeekMarch := PBCL_DateTimeDayOfWeek_1(LastDayMarch);
DayOfWeekOctober := PBCL_DateTimeDayOfWeek_1(LastDayOctober);
DaysToSubtractMarch := DayOfWeekMarch MOD 7;
DaysToSubtractOctober := DayOfWeekOctober MOD 7;
DST_Start := CONCAT_LDT(UtcYear, 3, 31 - DaysToSubtractMarch, 23, 59, 59,00,00,00);
DST_End := CONCAT_LDT(UtcYear, 10, 31 - DaysToSubtractOctober, 23, 59, 59,00,00,00);
IF (TodayDate2 >= DST_Start) AND (TodayDate2 <= DST_End) THEN
IsDst := TRUE;
ELSE
IsDst := FALSE;
END_IF
IF IsDst THEN
LocalHours := UtcHours +2;
ELSE
LocalHours := UtcHours +1;
END_IF’‘’