CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    [RESOLVED] Milliseconds using ColeDateTime

    According to MSDN, ColeDateTime has resolution of 1 millisecond but when I try to use add 0.002 seconds to a ColeDateTime object and try to output the seconds using GetSecond(), I still get an integer of seconds.

    Can I print the milliseconds instead?

    I did do some google search but couldn't find a definite answer. My problem is I have two times given tstart 11:13:26.001 (11am, 13 min, 26 second, 1 milliseconds) and tend in format like 11:17:13.001. I want to get times every 0.002 seconds between tstart and tend.

    Thanks

  2. #2
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    Re: Milliseconds using ColeDateTime

    Is this problem that hard that there have been more than 50 views and still no could answer it.

  3. #3
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: Milliseconds using ColeDateTime

    1. GetSecond() returns the integer second between 0 and 59 ... it
    has nothing to do with millisec.

    2) you mentioned that you added 0.002 milliseconds. How did you
    do that ? If you add 0.002 to a COleDateTime object, that
    is the same as adding 172.8 seconds. ( adding 1.0 = 24 hours , not
    1 second).

    3) It is not clear why you are using COleDateTime for this (at
    least not to me).

    4) you can use the m_dt data member to get the date/time (the fractional
    part is the time ... as a fraction of 24 hours. So if the fractional part
    is 0.5, that is 12 hours).

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Milliseconds using ColeDateTime

    Beside what Philip Nicoletti already stated.

    Indeed, MSDN notes that COleDateTime keeps the time with an approximate resolution of 1 millisecond (better said, its underlying DATE member can do that).
    MSDN: Date and Time: Automation Support
    However (keeping an eye on "approximate" word above) the COleDateTime is designed to work with a resolution of 1 second.
    Probably, if someone tries to extend it for dealing with a higher resolution will get (floating point) calculation errors.
    Anyhow, there is not a good ideea to directly modify COleDateTime::m_dt.

    So,
    1. Use COleDateTime for a maximum resolution of 1 second.
    2. Do not directly modify COleDateTime::m_dt; instead, call COleDateTime methods or use COleDateTimeSpan to add relative time.


    If you need resolution of 1 millisecond, then write your own classes keeping, for example, a SYSTEMTIME structure.
    It's a little bit to sweat but, that's it!
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    Re: Milliseconds using ColeDateTime

    I do not have to use ColeDateTime but that is the only thing I came across with a working example. So, I implemented in my code.

    So, is there any example code for m_dt which plays with milliseconds. I am looking for a very simple example like sets some time in milliseconds, adds another milliseconds to it and then gets hour, minute, second, milliseconds from new time.

    Also while using ColeDateTime when I add 0.02 second ofcourse myseconds do not change.

    Thanks

  6. #6
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    Re: Milliseconds using ColeDateTime

    I think this is the solution since I can't use Boost:

    http://www.codeproject.com/KB/datetime/hightime.aspx

    But would love to hear your opinion about the above if you have any.
    Last edited by Learned; December 23rd, 2011 at 12:30 PM.

  7. #7
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    Re: Milliseconds using ColeDateTime

    The CHightime gives build erros with Visual Studio 2010 and I am not the only one having it.

  8. #8
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    Re: Milliseconds using ColeDateTime

    Ok if I try to use the prvious suggestion about SYSTEM time to write my own code, how do I do it.

    I want to give in a specified time and be able to add 0.002 milliseconds and get new time. But using SYSTEM time I do not see any constructor where I can specify my supplied time.

    Any hint is appreciated.

  9. #9
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Milliseconds using ColeDateTime

    Quote Originally Posted by Learned View Post
    The CHightime gives build erros with Visual Studio 2010 and I am not the only one having it.
    What build errors?
    Could you please post your test project that failed to build here?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  10. #10
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    Re: Milliseconds using ColeDateTime

    I wrote my own millisecond handler which still uses ColeDateTime but the kind of errors I was getting are:
    xxx needs ';' before xxx, etc and the errors were in files which I downloaded from code project website. And there were tonnes of such error.

    I will just consider this thread as resolved since I am not prusuing this path anymore.

  11. #11
    Join Date
    Sep 2015
    Posts
    1

    Re: Milliseconds using ColeDateTime

    Quote Originally Posted by VladimirF View Post
    What build errors?
    Could you please post your test project that failed to build here?
    Hi
    I have similar compilation errors.
    Can anyone help if I post the errors here?

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Milliseconds using ColeDateTime

    Quote Originally Posted by Azeem.tp View Post
    Hi
    I have similar compilation errors.
    Can anyone help if I post the errors here?
    Just post it and we will try to help...
    Victor Nijegorodov

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