FB_TzSpecificLocalTimeToFileTime
The function block converts the local time (file time format) to UTC time (file time format), considering the specified time zone information. The function block FB _TzSpecificLocalTimeToSystemTime has similar functionality but uses a different time format (structured system time format).
The block is only suitable for conversion of continuous local timestamp information. Step changes in local time caused by daylight-saving/standard 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 to be able to identify the daylight-saving/standard 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 must be converted to a linear UTC time. It is therefore advisable to use the (continuous) UTC time for timestamping tasks and to convert the time to respective local time only for display purposes (e.g. in a visualization).
1. Graphic representation of the changeover from daylight-saving time to standard time (tzInfo = WEST_EUROPE_TZI ):
The local time (green) jumps back. The UTC output time (red) continuous. The local time: 02h:59m:59s:999ms.. is directly followed by: 02h:00m:00s:000ms.. The times between 2h and 3h occur twice. The duplicate time before the changeover is referred to as 02:05:00 CEST A , for example, the time after the changeover as 02:05:00 CET B. The output variable bB indicates whether it is the first or the second pass. During the second pass the bB output variable (blue) is set to TRUE. The bB output variable is automatically reset once the duplicate time has passed. The time zone ID (orange) changes from eTimeZoneID_Daylight (daylight-saving time) to eTimeZoneID_Standard (standard time).
2. Graphic representation of the change-over from standard time to daylight-saving time (tzInfo = WEST_EUROPE_TZI ):
The local time (green) jumps forward. The UTC output time (red) continuous. The local time: 2h:59m:59s:999ms.. is directly followed by: 3h:00m:00s:000ms.. The time zone ID (orange) changes from eTimeZoneID_Standard (standard time) to eTimeZoneID_Daylight (daylight-saving time).
VAR_INPUT
VAR_INPUT
in : T_FILETIME;
info : ST_TimeZoneInformation;
END_VAR
in: Local time (file time format) to be converted.
tzInfo: Structure variable with the current time zone information of the operating system.
VAR_OUTPUT
VAR_OUTPUT
out : T_FILETIME;
eTzID : E_TimeZoneID := eTimeZoneID_Unknown;
bB : BOOL;
ND_VAR
out: Converted UTC time (file time format).
eTzID: Additional daylight-saving/standard time information.
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:
The local time: DT#2011-09-02-11:01:31 is converted UTC time: DT#2011-09-02-09:01:31.
PROGRAM MAIN
VAR
in : DT := DT#2011-09-02-11:01:31;(* Local time *)
out : DT;(* UTC time *)
fbToUTC : FB_TzSpecificLocalTimeToFileTime;
END_VAR
fbToUTC( in := DT_TO_FILETIME( in ), tzInfo := WEST_EUROPE_TZI );
out := FILETIME_TO_DT( fbToUTC.out );
Further time and time zone functions and function blocks:
FB_TzSpecificLocalTimeToSystemTime, FB_TzSpecificLocalTimeToFileTime, FB_SystemTimeToTzSpecificLocalTime, FB_FileTimeTimeToTzSpecificLocalTime, FB_GetTimeZoneInformation, FB_SetTimeZoneInformation, NT_SetLocalTime, NT_GetTime, NT_SetTimeToRTCTime, F_TranslateFileTimeBias, FB_LocalSystemTime
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v2.11.0 Build > 2036 | PC or CX (x86, ARM) | TcUtilities.Lib |