Skip to content

Getting Current Local Time

edited April 2020 in PLCnext Engineer

I am struggling to capture the current time in the local timezone. The controller is synced with a NTP server. I set the timezone to US Eastern and the $ date command returns the correct time in the correct timezone. I first tried using the PBCL_DateTimeGetString FB from the PLCnextBase library. It returns the correct UTC time. I tried creating a C# FB that used DateTime.UtcNow.ToLocalTime() but that still returned UTC time. It was suggested in this post to create C++ FB, but unfortunately I am unfamiliar with C++ development. Also, I have tested this on 2019.9 & 2020.0 with the same results. Any suggestions?

Thanks, 

Rob

Comments

  • Hi Rob, I'm sure you've tried it, but out of interest, what does DateTime.Now() give you?

    ~ Martin.

  • Hi Rob, I'm sure you've tried it, but out of interest, what does DateTime.Now() give you?

    ~ Martin.

    DateTime.Now also returns UTC time. 

  • Hi Rob,

    I have reproduced the problem you are seeing with the DateTime.Now function. This seems like a bug to me, but I will check this with the experts here.

    ~ Martin.

  • Hi Rob,

    A short update.

    It is possible to get the local time using the "RTC" system variable in PLCnext Engineer. This variable has been introduced in a recent version of PLCnext Engineer, and wasn't available at the time of the earlier post you linked.

    I will find out the answer to the DateTime.Now question and post it here, in case you are interested, and for future reference.

    ~ Martin.

  • Martin, 

    Go to know about the RTC clock. That will solve my immediate problem. 

    I also contacted the PLCnextBase developers. They mentioned a new release with FB's for UTC to Local Time and more. That will be ideal. 

    Thanks for the quick repsonse, 

    Rob 

  • For others interested in this issue, it has now been confirmed that the problem with DateTime values described in this thread is a bug in the firmware (as at version 2020.3.1), and will be fixed in a future release.

    Sorry for the inconvenience.

    ~ Martin.

  • In the interests of closure:

    This issue has been fixed in FW 2020.6.1. From the change notes:

    From this version on, the block "RTC_S" returns the local time, provided a time zone with root rights has been set before. In previous versions, the UTC time was always returned.

    This solution is provided by a bug-fix that also fixes the DateTime.Now issue discussed in this thread.

    ~ Martin.

Sign In or Register to comment.