Can anyone please clarify whether SysRtcGetTime() returns UTC or whether it is corrected for the PLC's time zone setting? The description of the function implies that it is UTC as it says it is the number of seconds since 01-01-1970 but I just want to be sure as I have some odd time shift things going on (and I don't have the PLC in front of me).
Or could it be DT_TO_STRING which is 'correcting' the time to local time?
Thanks
Tony
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2016-11-28
Originally created by: scott_cunningham
For the CoDeSys Win V3 device, SysRtcGetTime() from SysRtc23 appears to return DT in UTC - at least it calculates the time based on the PC's current time and time zone settings.
Maybe you can assume for the CoDeSys RTE V3 device you get the same results... Be a bit careful, however, it could be hardware dependent... I use some embedded devices that have real time clocks, but no place to set a time zone or daylight savings time, etc. For these devices, SysRtcGetTime() gives my the set time on my device.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Another way of doing it can be by using these, but maybe this is more oftenly used inside embedded systems without a "Windows" user environment.
DTU.GetDateAndTime
DTU.SetTimeZoneInformation
First you do a one time initialization upon boot like this:
fbSetTimeZone(xExecute:=TRUE, tziInfo:=DTU.GlobalConstants.gc_tziTimeZoneCET);
Once that has been executed successfully you can retrieve the time like this whenever you want:
fbGetDateAndTime(xExecute:=<insert here="" your="" condition="">);</insert>
To create a nice string I usually make use of the Oscat DT_TO_STRF function:
g_sCurrentDateTime:=BASIC.DT_TO_STRF(DTI:=fbGetDateAndTime.dtDateAndTime, MS:=0, FMT:='#A-#D-#H #N:#R:#T', LANG:=BASIC.LANGUAGE.DEFAULT);
This will return a string looking like this "2016-11-30 09:37:43"
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Can anyone please clarify whether SysRtcGetTime() returns UTC or whether it is corrected for the PLC's time zone setting? The description of the function implies that it is UTC as it says it is the number of seconds since 01-01-1970 but I just want to be sure as I have some odd time shift things going on (and I don't have the PLC in front of me).
Or could it be DT_TO_STRING which is 'correcting' the time to local time?
Thanks
Tony
Originally created by: scott_cunningham
For the CoDeSys Win V3 device, SysRtcGetTime() from SysRtc23 appears to return DT in UTC - at least it calculates the time based on the PC's current time and time zone settings.
Maybe you can assume for the CoDeSys RTE V3 device you get the same results... Be a bit careful, however, it could be hardware dependent... I use some embedded devices that have real time clocks, but no place to set a time zone or daylight savings time, etc. For these devices, SysRtcGetTime() gives my the set time on my device.
Another way of doing it can be by using these, but maybe this is more oftenly used inside embedded systems without a "Windows" user environment.
DTU.GetDateAndTime
DTU.SetTimeZoneInformation
First you do a one time initialization upon boot like this:
fbSetTimeZone(xExecute:=TRUE, tziInfo:=DTU.GlobalConstants.gc_tziTimeZoneCET);
Once that has been executed successfully you can retrieve the time like this whenever you want:
fbGetDateAndTime(xExecute:=<insert here="" your="" condition="">);</insert>
To create a nice string I usually make use of the Oscat DT_TO_STRF function:
g_sCurrentDateTime:=BASIC.DT_TO_STRF(DTI:=fbGetDateAndTime.dtDateAndTime, MS:=0, FMT:='#A-#D-#H #N:#R:#T', LANG:=BASIC.LANGUAGE.DEFAULT);
This will return a string looking like this "2016-11-30 09:37:43"