Join us today!

Get System Local Ti...
 
Notifications
Clear all

Get System Local Time

1 Posts
1 Users
1 Reactions
789 Views
TwinControls
Posts: 71
Admin
Topic starter
(@beckhoffsupport)
Member
Joined: 2 years ago

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. 

utilitieslib
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);

 

systemTime

 

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;

 

Reply
Share: