Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting a Labview time into a string with Measurement Studio C++

In my Measurement Studio-based C++ application, I'll be sent a Labview time in the format of a double, which I believe is seconds since 1904. Does Measurement Studio for Visual C++ contain a function that will convert that time value into a string format? I'd like to end up with something like "hh:mm:ss:msec". I'm basically looking for the equivalent of the Labview vi, "Format Time/Date String". If Measurement Studio doesn't provide this, is there some other (hopefully simple) way to do this?

I can request that the Labview application send me time in a string format as well as a double; this will require several changes to the Labview application sending the timestamp, but if that is a simpler solution that's the option we'll take.

Thanks in advance,

Adam

0 Kudos
Message 1 of 4
(3,822 Views)
Measurement Studio does not have a function for this, but you can do this yourself by first converting from LV epoch (1/1/1904) to Unix epoch(1/1/1970) and then using c runtime time functions

UNIXEpochOffset is the difference between the 2 epochs at GMT. To convert to a UNIX system clock value, just subtract the sum of this number and your time zone offset in seconds

lvTime is the value returned by LV timestamp

#define  UNIXEpochOffset 2082844800

int _tmain(int argc, _TCHAR* argv[])
{
    __int64 lvTime = 3214396284; //10:48:13.173 AM 11/9/2005
   

    //GMT offset for Central Time is -6 (3600 seconds). You will need to account for daylight savings time.
    int offset = -3600;
    time_t unixTime = lvTime - UNIXEpochOffset - offset;  

    struct tm *newtime = localtime(&unixTime);
    printf(asctime( newtime )); //prints out the time in a string format.


    return 0;
}

Bilal Durrani
NI
0 Kudos
Message 2 of 4
(3,806 Views)

Hey Adam,

It would be way easier to do it in LabVIEW.   If you are using a LabVIEW version older than 8.0 then your time will be limited to 1904 whereas in 8.0 your time can go back as far as 0001. I hope this is helpful

Message Edited by Sam R on 11-09-2005 11:44 AM

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 3 of 4
(3,804 Views)
I took Bilal's suggestion, and it's working for me. The only difference I found was that I didn't need the offset; probably the labview time value being sent to me is in the local time zone. Thanks for the responses!

0 Kudos
Message 4 of 4
(3,795 Views)