Need VC++ 6.0 version of .NET C# CDateTime

Note: I do not need a timer I need a class to do Date Time math

The CTime class in MFC is only accurate to the second.

In .NET I can  initalize a CDateTime to yyyy-mm-dd HH:MM:SS.uuuuuuu  where uuuu are microseconds. I can also .add(ticks) where ticks are 100 nanosecond increments

why: I read data stored by test equipment the data values are Date Time stamped to the microsecond as ASCII strings. I need to be able to do math to determine differences that may be less than a second. I also need to format output strings that will look like the input strings

Anyone know of a VC++ class that will fit the criteria

needs overloaded operators, copy constructures etc.

TIA
Dan
dbrancaAsked:
Who is Participating?
 
waysideConnect With a Mentor Commented:
Well, the page on codeproject specifically shows a .Format function, and says the format codes are the smae as for COleDateTime, with %s, %u, and %n for milliseconds, microseconds, and nanoseconds.

There are two forms of the .Format, a non-MFC and MFC version.

For non-MFC, you would use:

char buf[101];

shdt.Format(buf, 100, "%m-%d-%Y %H:%M:%S.%s%u");

For MFC, you would use:

CString date - shdt.Format("%m-%d-%Y %H:%M:%S.%s%u");

Did you try these functions?
0
 
mahesh1402Commented:
Have a look at  Windows API functions QueryPerformanceFrequency() and QueryPerformanceCounter() for getting the frequency and respectively the counts of the high-resolution performance counter in micro seconds.

Have a look at C++ class for more precise time interval measurement in which above API functions used :
http://www.codeproject.com/cpp/precisetimer.asp <== CPreciseTimer class is having functions  StartTimer() StopTimer() GetTime() to measure time intervals in microseconds under Windows OS.


Another article you may have a look regarding this is 'CCPUTicker : Precision Timing'
http://www.codeproject.com/datetime/ccputicker.asp

You may also use GetTickCount API but that will be able to get time in miliseconds only.

-MAHESH
0
 
mahesh1402Commented:
e.g for your purpose you may use above CPreciseTimer::GetTime() function to retrieve time interval in 'microseconds'

Have a look at this High Resolution Date-Time Class too : http://www.codeproject.com/datetime/hightime.asp <== you may use CHighTime and CHighTimeSpan classes to count time in microseconds

-MAHESH
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
waysideCommented:
Here's a class that may fit your needs:

CHighTime - http://www.codeproject.com/datetime/hightime.asp

The claims to resolve to 0.1 microseconds, and has a format function to output times in any way you like. It also includes a CHighTimeSpan class for adding and subtracting times. It seems to be modelled after COleDateTime, which is nice but only has a  second resolution.
0
 
dbrancaAuthor Commented:
Thanks guys
But...
Mahesh ... I specifically stated " Note: I do not need a timer" again what I was hoping for was exactly what the .net c# CDateTime class does

Mahesh
wayside:
I have already looked at CHighDateTime

yes, on the right track, with CHighDateTime and CHighTimeSpan - the only problem is that I specifically need to be able to do something like chdt.ToString(strFormat) and get back
06-30-2006 14:23:18.000234  although CHighDateTime looks good, the author didn't feel the string out put would be of any use
0
 
mahesh1402Commented:
>>Here's a class that may fit your needs:

wayside
that was not I already suggested ?

-MAHESH
0
 
waysideCommented:
Sorry Mahesh, I missed that in your post.
0
 
mahesh1402Commented:
never mind ;)
0
 
dbrancaAuthor Commented:
Mahesh
I missed it too, specifically because your post started out with discussion about timers. I specifically wrote I did not want a timer. I did the google search also. I too found hightime. I saw a number of questions from people asking for a high resolution DateTime class. In almost every case people answered by suggesting high resolution timers. This is why I rarely use these kinds of users groups. They are filled with so much noise. Just when you think you have found an answer it is usualy someone with the same problem asking to be notified when you find a solution, someone who questions your reason for wanting the utility in the first place, or someone who answers a different question completely.

I came here for expert help the one piece of expert help I got was this
("%m-%d-%Y %H:%M:%S.%s%u")  I had trouble finding this format string

The real problem is with all the noise google indexes everything
0
 
mahesh1402Commented:
well may be I lead to post that link due to your post <Need VC++ 6.0 version of .NET C# CDateTime> and <Anyone know of a VC++ class that will fit the criteria>..and cannot post you further for your query regarding format string because of my timezone..

Anways its nice to see your got a solution ! :)

-MAHESH
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.