Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-07-19
10
Medium Priority
?
589 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:dbranca
  • 5
  • 3
  • 2
10 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17143623
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17143846
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
 
LVL 14

Expert Comment

by:wayside
ID: 17150652
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dbranca
ID: 17151182
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
 
LVL 14

Accepted Solution

by:
wayside earned 2000 total points
ID: 17151294
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17151526
>>Here's a class that may fit your needs:

wayside
that was not I already suggested ?

-MAHESH
0
 
LVL 14

Expert Comment

by:wayside
ID: 17153434
Sorry Mahesh, I missed that in your post.
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17153606
never mind ;)
0
 

Author Comment

by:dbranca
ID: 17154741
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17155159
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question