F_TranslateFileTime64Bias
This function converts the input time to the time in another time zone based on the specified bias time shift. The function can be used to convert the local time to UTC time (Universal Time Coordinates) and vice versa, for example.
FUNCTION F_TranslateFileTime64Bias: T_FILETIME64
Inputs
VAR_INPUT
in : T_FILETIME64;
bias : DINT;
toUTC : BOOL;
END_VAR
Name | Type | Description |
---|---|---|
in | Input time to be converted. | |
bias | DINT | Difference between UTC time and local time in minutes (positive or negative values are permitted) |
toUTC | BOOL | This parameter can be used to specify the direction in which the input time is to be converted. |
toUTC | Direction | Internal formula |
---|---|---|
FALSE | UTC -> local time | Local time := UTC - bias |
TRUE | Local time -> UTC | UTC := local time + bias |
Example:
The in variable contains the time to be converted. The bToUTC variable determines the conversion direction. If bToUTC = TRUE, the local time is converted to UTC time, if bToUTC = FALSE, the UTC time is converted to local time. The WEST_EUROPE_TZI constant contains the time zone information for Western Europe. The required bias value is calculated from the time zone information in the constant and the current bDST setting (Daylight Saving Time). Alternatively, the current time zone information of a TwinCAT system can be determined with the function block: FB_GetTimeZoneInformation.
Important note: Data type DT was selected for the input time because of the visual control option in online mode. Conversions to other time formats are not necessarily recommend since the conversion functions can be very computing-intensive.
PROGRAM MAIN
VAR
bDST : BOOL := TRUE;(* TRUE => Daylight saving time, FALSE => Standard time *)
bToUTC : BOOL := FALSE;(* TRUE => Convert local time to UTC time, FALSE => Convert UTC time to local time *)
in : DT := DT#2011-08-29-15:15:31;
out : DT;
bias : DINT;
END_VAR
IF bDST THEN
bias := WEST_EUROPE_TZI.bias + WEST_EUROPE_TZI.daylightBias;
ELSE
bias := WEST_EUROPE_TZI.bias + WEST_EUROPE_TZI.standardBias;
END_IF
out := FILETIME64_TO_DT( F_TranslateFileTime64Bias( DT_TO_FILETIME64( in ), bias, bToUTC ) );
Further time and time zone functions and function blocks:
- FB_TzSpecificLocalTimeToSystemTime
- FB_TzSpecificLocalTimeToFileTime64
- FB_SystemTimeToTzSpecificLocalTime
- FB_FileTime46ToTzSpecificLocalTime
- FB_GetTimeZoneInformation
- FB_SetTimeZoneInformation
- NT_SetLocalTime
- NT_GetTime
- NT_SetTimeToRTCTime
- FB_LocalSystemTime
Requirements
Development environment | Target platform | PLC libraries to be integrated (category group) |
---|---|---|
TwinCAT v3.1.4024 | PC or CX (x86, x64, ARM) | Tc2_Utilities (System) >= 3.3.44.0 |