This widget could not be displayed.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get a UTC timestamp?

Solved!
Go to solution

 

The "Get Date Time in Seconds" VI does not have a UTC option. I have an application that needs the UTC as a timestamp.

 

I could use the "Seconds to Date/Time" with the UTC input as True.  The output of this gives me the UTC in a cluster.  This is shown in the upper branch of the VI above.  The output shows me the correct UTC.

 

To try and get around this, I used the "Seconds to Date/Time" with the UTC input as True, followed by a "Date/Time to Seconds" with the UTC input as False.  This is shown in the bottom branch of the VI above.  I expected the output of this to give me the UTC as a time stamp.

 

Here's the problem: for some reason, the Time stamp output is 1 hour ahead of the real UTC.  Can anybody explain this?  Any workaround?

S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
Message 1 of 19
(11,279 Views)

You've got to deal with "is DST?" 


"Should be" isn't "Is" -Jay
Message 2 of 19
(11,269 Views)

None of those VIs has a "Is DST?" parameter.

S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
0 Kudos
Message 3 of 19
(11,259 Views)
Solution
Accepted by topic author _S_G

Hi SG,

 

well, the "date time rec" cluster has...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 19
(11,243 Views)

Thanks, that worked.  The solution I finally used was

 

S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
0 Kudos
Message 5 of 19
(11,198 Views)

Be careful; the code is doing something a little different what you think it is doing, and won't work correctly during daylight savings time transitions.

 

LabView timestamps (the underlying numeric data on the wire) are always in UTC. The conversion to localtime is done only when a timestamp is displayed in a timestamp control/indicator/constant or written out to a string. You can verify this by casting a timestamp to a double. 

 

If the problem is "how do I am make the timestamp control display UTC?", that is best done via a custom format: use the %^<>T container in "display properties":

 

displayprops.png

 

Non-obviously, this setting applies to constants also. If you set a constant using the default (localtime) view, then quit LV, change your timezone, and restart, the constant will appear to change. It hasn't really changed, in that the underlying number-of-seconds-since-1904 is still the same, it's just displaying it differently. (It would be nice if LabView gave us some kind of visual to indicate whether a control/indicator/timestamp is showing local or universal time.)

 

The problem with the code above is that it says "display a localtime that has the same numeric digits as the current UTC time". It modifies the time on the wire to represent a different time than "now"; it's "now" offset from "now" by your TZ offset. The second is doing it this way will work "most of the time" but it has weird quirks (ask me how I know!) during daylight savings time transitions. For example, the UTC time string "2014-03-09 02:30" is a perfectly valid UTC time, but does not exist in the Eastern Time Zone: passing this time with UTC = F to Date/Time to Seconds will return the UTC time associated with "2014-03-09 03:30", and that's what will be displayed on the timestamp.

Message 6 of 19
(10,656 Views)

Hi, could you explain better your solution? I need to get UTC date/time in seconds.

 

0 Kudos
Message 7 of 19
(5,837 Views)

Hi sorin,

 


@sorin1 wrote:

 I need to get UTC date/time in seconds.


This will give you UTC data in a cluster:

What is the required output format? How many "seconds" do you need?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 19
(5,826 Views)

For example, if UTC date&time is March 26, 2020 16:50:04 (UTC), the value is 3668086204 seconds

0 Kudos
Message 9 of 19
(5,820 Views)

@sorin1 wrote:

For example, if UTC date&time is March 26, 2020 16:50:04 (UTC), the value is 3668086204 seconds


Where is this UTC date&time coming from?  Is it a string?  A timestamp input on the front panel?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 19
(5,816 Views)