06-16-2011 05:49 PM - edited 06-16-2011 05:51 PM
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?
Solved! Go to Solution.
06-16-2011 07:30 PM
You've got to deal with "is DST?"
06-16-2011 09:26 PM
None of those VIs has a "Is DST?" parameter.
06-17-2011 01:54 AM
06-23-2011 12:35 PM
Thanks, that worked. The solution I finally used was
03-12-2014 11:03 AM
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":
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.
06-22-2020 06:55 AM
Hi, could you explain better your solution? I need to get UTC date/time in seconds.
06-22-2020 07:58 AM - edited 06-22-2020 07:59 AM
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?
06-22-2020 08:03 AM
For example, if UTC date&time is March 26, 2020 16:50:04 (UTC), the value is 3668086204 seconds
06-22-2020 08:11 AM
@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?