Jump to content

How to convert millisecond time to current time and vise verse.


pravin

Recommended Posts

I'm not sure exactly what you're after, you want a millisecond time relative to what? Your VI calculates it from the beginning of the current day, is that what you're after? Essentially you need to define an epoch-- what it is you're measuring your millisecond time relative to if you want to be able to convert back and forth between the native LabVIEW time format. If you pull out the milliseconds elapsed since the beginning of the day, when you go back to the native type you need to add back in the absolute time you dropped when you shifted your epoch.

Hint: the time type in LabVIEW is measured from the 0:00 UTC January 1 1904 epoch and is a 128 bit second based measurement. You can convert it to a DBL to obtain the number of seconds at a possible loss of precision and range, or cast it as a cluster of {I64, U64} numbers without the loss (reference). The signed integer is number of seconds since the epoch (signed to allow times prior to the epoch) and the unsigned integer is the positive fraction of a second.

post-11742-0-01416000-1393422736_thumb.p

 

Edit: Added the wrong snippet, should be fixed now.

Link to comment

Several issues with your code.  The first is a race condition where you are converting to string, then try to convert back using a local variable.  You are reading that variable, and writing to it at the same time and you have no idea who read or wrote to it first.

 

I see you pulling out all of the components of time then adding them, then converting to a U64.  A U64 doesn't have a fractional component, but you are adding fractional seconds.  This means your resolution will only be 1 second not 1 millisecond.  I'm also not sure why you are only interested in the time component and not the date.  This maybe a requirement of some kind but I thought it odd and actually didn't notice until just now but I already wrote a working conversion to a hex string and back that contain the date.  I'd also use a time constant or control for the time stamp instead of current time.  Current time changes each time you run and having a constant (or control) allows you to run it and see where the conversion isn't working.

 

My attached code takes the time stamp.  Multiplies it by 1000 so we are now looking at the number of milliseconds not seconds.  Then put that into a U64, and convert to string.  The reverse is just as simple.  Convert string to hex, divide by 1000 then convert back into a time stamp.

hex to String and back.vi

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.