CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2007
    Posts
    97

    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

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Best way to handle MMM DD HH:MM:SS.MMM Timestamps?

    Quote Originally Posted by rudyloo View Post
    ...
    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

  3. #3
    Join Date
    Jan 2007
    Posts
    97

    Re: Best way to handle MMM DD HH:MM:SS.MMM Timestamps?

    Quote Originally Posted by VictorN View Post
    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

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  5. #5
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    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)

  6. #6
    Join Date
    Jan 2007
    Posts
    97

    Re: Best way to handle MMM DD HH:MM:SS.MMM Timestamps?

    Thanks all.

    I found this link helpful as well.
    http://forums.codeguru.com/showthrea...IME-difference

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Best way to handle MMM DD HH:MM:SS.MMM Timestamps?

    Quote Originally Posted by rudyloo View Post
    Thanks all.

    I found this link helpful as well.
    http://forums.codeguru.com/showthrea...IME-difference
    You may find the COleDateTime class helpful too. It has a method for parsing times in string format.

  8. #8
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Best way to handle MMM DD HH:MM:SS.MMM Timestamps?

    Quote Originally Posted by GCDEF View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured