LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting seconds to a date in another language

Solved!
Go to solution

Hello all,

 

I am currently working on an application that uses web services to populate a web-based UI.  One of the outputs is a measurement time that is generated using the LabVIEW method 'Get Date/Time in Seconds'.  To make since of this, I convert the value to a double precision float and transmit it to the host (on request).  On the host side, I am using Javascript to populate a text box with the current measurement date and time.  To do this, I use the followign code

 

var dateobj = new Date(1904,1,1);

/* The variable 'time' should be the seconds since 
 * midnight 1 Jan 1904 of the current measurement.
 */
var measTime = dateobj.setSeconds(time);

 When I do this, what I find is that the time is actually one month off.  I can correct this by changing the date in the creation of my 'dateobj' to 1 Dec 1903.  Has anyone seen this before, possibly in another language?  It is not beyond the realm of reason that I am doing something incorrectly, but I can't seem to get at what right now.

 

Thanks, Matt

0 Kudos
Message 1 of 22
(4,176 Views)

Just a guess. It might be related to the fact that 1904 is well before the beginning of time in the linux/unix world. 

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 22
(4,131 Views)

It's well before time started on all computers.  He's likely using that date in reference to this: http://zone.ni.com/reference/en-XX/help/371361H-01/glang/get_date_time_in_seconds/

 

There's an easy way to determine if that is the issue.  You can feed a shorter time just to see if it reads correctly rather than a more recent time.  I don't work with Java enough to know if the methods you're calling are related to a defined class or one you've built.  I'd imagine they have a Date API for you already.  If so, I'd expect it could handle those kinds of calculations.  Have you looked at their API to see if you're making a correct call?

0 Kudos
Message 3 of 22
(4,116 Views)
Thanks, Mike, but I am pretty sure that that is not it. LabVIEW is built on c, more Unix-y than JavaScript, so my feeling is that there is something that I must be misunderstanding here. It is likely the js date function works much in the same way as the lv date functions...
0 Kudos
Message 4 of 22
(4,115 Views)

Not that I'm offering anything new here bu,t I wonder if it could be somewhat related to a known issue where Crash reports would post a month in the future

 

Darn it CA- I can't find the bug thread or CAR! and I know that "crash report in the future" had both!

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 22
(4,098 Views)

Hmmmm...that's intriguing....  I need to do some more thorough experimenting to see if I can reproduce this behavior and if there is some point at which it all flips and problem goes away.  I am pretty sure that like Teststand, time is referenced to 1970 rather than 1904.  I will look into this and try to provide some more details.  I was hoping that someone would pop up and say that they had done this before and had no problems; but, I may be a bit optimistic...

0 Kudos
Message 6 of 22
(4,095 Views)

@mtat76 wrote:

Hmmmm...that's intriguing....  I need to do some more thorough experimenting to see if I can reproduce this behavior and if there is some point at which it all flips and problem goes away.  I am pretty sure that like Teststand, time is referenced to 1970 rather than 1904.  I will look into this and try to provide some more details.  I was hoping that someone would pop up and say that they had done this before and had no problems; but, I may be a bit optimistic...



Epoch for LabVIEW IS the non-existant second before midnight on Jan 1 1904,  Leap secods are un-accounted for to the best of my knowlegde. and since 1904 WAS a leap year the Lotus" phantom 1900 Feb 29 does not pertain at all.  

 

The "one month off issue" bares investigation.  I Know Altenbach reported that happened with NI Error Reporting Service logs but, my Google skills fail me and I never did read a "First cause" analisys of the resolution. (The CAR is closed:  Read that as "Maybe someone at NI found a viable workaround")


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 22
(4,090 Views)

Which CAR was it?  I'll try my google skills.  Maybe I'll get lucky?

0 Kudos
Message 8 of 22
(4,085 Views)
Solution
Accepted by topic author cirrusio

OK...this is pretty lame, but turns out to be a js issue and not a LV issue.  Month's are 0 based!  Sooooo... Jan == 0 in js world.  Ugh..case closed.  For those interested, here is an example:

 

http://jsfiddle.net/4gc9r8gy/2/

Message 9 of 22
(4,082 Views)

Interesting.  That makes you wonder why choosing the 13th month didn't throw an error

0 Kudos
Message 10 of 22
(4,075 Views)