|
-
December 22nd, 2011, 11:12 AM
#1
[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
-
December 22nd, 2011, 06:30 PM
#2
Re: Milliseconds using ColeDateTime
Is this problem that hard that there have been more than 50 views and still no could answer it.
-
December 22nd, 2011, 08:55 PM
#3
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).
-
December 23rd, 2011, 05:50 AM
#4
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,
- Use COleDateTime for a maximum resolution of 1 second.
- 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!
-
December 23rd, 2011, 09:27 AM
#5
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
-
December 23rd, 2011, 12:25 PM
#6
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.
-
December 23rd, 2011, 02:49 PM
#7
Re: Milliseconds using ColeDateTime
The CHightime gives build erros with Visual Studio 2010 and I am not the only one having it.
-
December 23rd, 2011, 03:11 PM
#8
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.
-
December 23rd, 2011, 03:53 PM
#9
Re: Milliseconds using ColeDateTime
 Originally Posted by Learned
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...
-
December 23rd, 2011, 06:56 PM
#10
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.
-
September 28th, 2015, 12:06 PM
#11
Re: Milliseconds using ColeDateTime
 Originally Posted by VladimirF
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?
-
October 2nd, 2015, 03:03 PM
#12
Re: Milliseconds using ColeDateTime
 Originally Posted by Azeem.tp
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|