FB_TzSpecificLocalTimeToSystemTime

FB_TzSpecificLocalTimeToSystemTime 1:

The function block converts the local time (structured system time format) to UTC time (structured system time format), taking into account the specified time zone information. The function block FB_TzSpecificLocalTimeToFileTime has similar functionality but uses a different time format (file time format).

The block is only suitable for conversion of continuous local timestamp information. Step changes in local time caused by summer/winter time changeover are permitted and are correctly detected by the block. Arbitrary changes in local time result in incorrect conversion. The reason: the last converted time is stored internally in block in order to be able to identify the summer time/winter time information and the B times (see below) when the local time is reset. The block is associated with an action: A_Reset(). If this action is called the block outputs and the locally stored (last converted) time are reset to zero.

The step changes in the local time are problematic, since they have to be converted to a linear UTC time. It is therefore advisable to use the (continuous) UTC time for time stamping tasks and to convert the time to respective local time only for display purposes (e.g. in a visualization).

Further information can be found in the documentation for the FB_TzSpecificLocalTimeToFileTime function block.

VAR_INPUT

VAR_INPUT
    in     : TIMESTRUCT;
    tzInfo : ST_TimeZoneInformation;
END_VAR

in: Local time (structured system time format) to be converted (type: TIMESTRUCT).

tzInfo: Structure variable with the current time zone information of the operating system (type: ST_TimeZoneInformation).

VAR_OUTPUT

VAR_OUTPUT
    out    : TIMESTRUCT;
    eTzID  : E_TimeZoneID := eTimeZoneID_Unknown;
    bB     : BOOL;
END_VAR

out: Converted UTC time (structured system time format) (type: TIMESTRUCT).

eTzID: Additional summer/winter time information (type: E_TimeZoneID).

bB: TRUE => B time (e.g.:02:05:00 CET B), FALSE => other time (e.g.: 02:05:00 CEST A). This output is set if the local time jumps back and is reset once the duplicate local time has passed.

Example:

PROGRAM MAIN
VAR
    in      : TIMESTRUCT := ( wYear := 2011, wMonth := 4, wDay := 29, wHour := 16, wMinute := 46, wSecond := 31, wMilliseconds := 99 );(* Local time *)
    out     : TIMESTRUCT;(* UTC time result is:= ( wYear := 2011, wMonth := 4, wDay := 29, wHour := 14, wMinute := 46, wSecond := 31, wMilliseconds := 99 ) *)
    fbToUTC : FB_TzSpecificLocalTimeToSystemTime;
END_VAR
fbToUTC( in := in, tzInfo := WEST_EUROPE_TZI, out => out );

Further functions and function blocks for time and time zone:

Requirements

Development environment

Target platform

PLC libraries to be integrated (category group)

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_Utilities (System)