-
October 9th, 2013, 03:27 PM
#1
Best way to handle MMM DD HH:MM:SS.MMM Timestamps?
Hi
I have a file where each line contains the following timestamp format:
MMM DD HH:MM:SS.MMM
I want to read this in and normalize the time and pass it along in seconds.
I am using the following at the moment. However it doesn't support milliseconds.
CTime time( m_year, month, day, hour, min, sec)
I read in first timestamp, save it in "firstTimeStamp" and then pass the rest of the line for processing with timestamp 0.
For any lines after that, I read in the timestamp, subtract "firstTimeStamp" using CTimeSpan and pass long.
Ideas on how I can include the milliseconds?
Thanks
-
October 9th, 2013, 04:00 PM
#2
Re: Best way to handle MMM DD HH:MM:SS.MMM Timestamps?
Originally Posted by rudyloo
...
I want to read this in and normalize the time and pass it along in seconds.
I am using the following at the moment. However it doesn't support milliseconds.
Why care about milliseconds if you pass the time along in seconds?
Victor Nijegorodov
-
October 9th, 2013, 04:17 PM
#3
Re: Best way to handle MMM DD HH:MM:SS.MMM Timestamps?
Originally Posted by VictorN
Why care about milliseconds if you pass the time along in seconds?
Hi
The logs contains data where milliseconds is needed.
Example:
Sep 29 02:13:04.150 example line 1 testing 1234 bla bla
Sep 29 02:13:05.855 example line 2 testing 1234 bla bla bla
First line would be passed with timestamp 0
Second line would be passed with timestamp 1.705 seconds
Thanks
-
October 9th, 2013, 04:28 PM
#4
Re: Best way to handle MMM DD HH:MM:SS.MMM Timestamps?
have a look at SYSTEMTIME structure and its Remark section:
Remarks
It is not recommended that you add and subtract values from the SYSTEMTIME structure to obtain relative times. Instead, you should
Convert the SYSTEMTIME structure to a FILETIME structure.
Copy the resulting FILETIME structure to a ULARGE_INTEGER structure.
Use normal 64-bit arithmetic on the ULARGE_INTEGER value.
Victor Nijegorodov
-
October 9th, 2013, 04:33 PM
#5
Re: Best way to handle MMM DD HH:MM:SS.MMM Timestamps?
Have a look at the SYSTEMTIME structure which supports milliseconds
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
The article also discusses how to perform relative time calculations which is what you require.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 10th, 2013, 04:08 PM
#6
Re: Best way to handle MMM DD HH:MM:SS.MMM Timestamps?
-
October 10th, 2013, 05:06 PM
#7
Re: Best way to handle MMM DD HH:MM:SS.MMM Timestamps?
Originally Posted by rudyloo
You may find the COleDateTime class helpful too. It has a method for parsing times in string format.
-
October 10th, 2013, 05:20 PM
#8
Re: Best way to handle MMM DD HH:MM:SS.MMM Timestamps?
Originally Posted by GCDEF
You may find the COleDateTime class helpful too. It has a method for parsing times in string format.
I don't think the COleDateTime class supports milliseconds?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|