Solved

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

Posted on 2006-07-19
10
578 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
 

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 500 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now