Best way to handle MMM DD HH:MM:SS.MMM Timestamps?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

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

  1. #1
    Join Date
    Jan 2007
    Posts
    96

    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 offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,271

    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
    96

    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 offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,271

    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
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  6. #6
    Join Date
    Jan 2007
    Posts
    96

    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
    Posts
    12,047

    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
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center