Join us today!
Get System Local Time
To get the local system time in TwinCAT, you can use FB_LocalSystemTime function block. You may use it when you need a timestamp for your errors, warnings, messages etc..
Add the Tc2_Utilities library.
VAR stLocalSystemTime : TIMESTRUCT; fbLocalSystemTime : FB_LocalSystemTime; bGetTime : BOOL; tTimeOut : TIME := DEFAULT_ADS_TIMEOUT; bLocalSystemTimeValid : BOOL; tzID : E_TimeZoneID := eTimeZoneID_Invalid; END_VAR fbLocalSystemTime( sNetID:= '', bEnable:= bGetTime, dwCycle:= 2, // cycle time (in seconds) , Synchronization every 2 seconds. dwOpt:= 1, //Bit 0: If this is set, the Windows system time is additionally synchronized cyclically with the hardware clock (RTC) (corresponds to the function NT_SetTimeToRTCTime). tTimeout:= tTimeOut, bValid=> bLocalSystemTimeValid, systemTime=> stLocalSystemTime, tzID=> tzID);
stLocaSystemTime is in system time format:
wYear: The year: 1970 ~ 2106;
wMonth: The month: 1 ~ 12 (January = 1, February = 2 etc.);
wDayOfWeek: The day of the week: 0 ~ 6 (Sunday = 0, Monday = 1 etc.);
wDay: The day of the month: 1 ~ 31;
wHour: Hour: 0 ~ 23;
wMinute: Minute: 0 ~ 59;
wSecond: Second: 0 ~ 59;
wMilliseconds: Millisecond: 0 ~ 999;
In case you want to say thank you !)
We'd be very grateful if you could share this community with your colleagues and friends. You can also buy us a coffee to keep us fueled 😊 This is the best way to say thank you to this project and support your community.
twinControls - https://twincontrols.com/
- 17 Forums
- 265 Topics
- 932 Posts
- 0 Online
- 689 Members