F_TranslateFileTime64Bias
![F_TranslateFileTime64Bias 1:](Images/gif/35855883__en-US__Web.gif)
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
VAR_INPUT
VAR_INPUT
in : T_FILETIME64;
bias : DINT;
toUTC : BOOL;
END_VAR
in: Input time that is to be converted (type: T_FILETIME64).
bias: Difference between UTC time and local time in minutes (positive or negative values are permitted).
toUTC: 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 |
Sample:
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). The current time zone information of a TwinCAT system can alternatively be determined with the function block: FB_GetTimeZoneInformation.
Important notice: 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:
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 |