locked
Convert integer to time/date RRS feed

  • Question

  • I have a card that outputs the date (starting Jan. 1, 1970) in seconds.  I was wondering if there is a way to convert this number into the current date/time.
    Monday, August 13, 2007 3:29 PM

Answers

  • The CRT time functions work in this format. So if you take the output from that card, assign it to a time_t variable and then use the ctime function, then you will get a string of the current date.

    The only other way is to write a function like this yourself which isn't too hard.

     

    Monday, August 13, 2007 5:16 PM

All replies

  • Is this native C++ or C++/CLI? Are you using MFC? You should narrow it down a bit.
    Monday, August 13, 2007 5:15 PM
  • The CRT time functions work in this format. So if you take the output from that card, assign it to a time_t variable and then use the ctime function, then you will get a string of the current date.

    The only other way is to write a function like this yourself which isn't too hard.

     

    Monday, August 13, 2007 5:16 PM
  • So I was able to interpret the date easily from your instructions but I have another question.  The device I am using also outputs the time down to the nanosecond as a separate variable.  I was wondering if there is any way to modify the output of ctime so I could simply print the nanoseconds next to seconds.
    Thursday, August 16, 2007 3:49 PM