stupid VC++ with timestamp
-
I have a dialog with 2 Date Time Picker. The first is m_date with Short Date format The second is m_time with Time format
CDateTimeCtrl dateBox; // Date Time Picker with Short Date format
CDateTimeCtrl timeBox; // Date Time Picker with Time formatThen I want to get the timestamp from them, the final result should be in __int64 (to compare with database and something else). An example is 1214878775000 for a SYSTEMTIME wYear 2008 wMonth 7 wDayOfWeek wDay 1 wHour 11 wMinute 19 wSecond 35 wMilliseconds 734 Try to look at the MSDN, there are many stupid things: CTime, SYSTEMTIME, FILETIME, .... blah blah .... with a alot of functions. Is it really that difficult or I go the wrong way? Does anyone have some way to to this? Here I got the result with a function like this way:
__int64 CMyDlg::getTimestamp()
{
__int64 nTime;CTime tmpTime; int nYear, nMonth, nDay, nHour, nMin, nSec; dateBox.GetTime( tmpTime ); nYear = tmpTime.GetYear(); nMonth = tmpTime.GetMonth(); nDay = tmpTime.GetDay(); timeBox.GetTime( tmpTime ); nHour = tmpTime.GetHour(); nMin = tmpTime.GetMinute(); nSec = tmpTime.GetSecond(); CTime navTime( nYear, nMonth, nDay, nHour, nMin, nSec ); SYSTEMTIME ST; FILETIME FT; navTime.GetAsSystemTime(ST); SystemTimeToFileTime(&ST,&FT); \_\_int64 nSetTime; memcpy(&nSetTime, &FT, sizeof(FILETIME)); MyFormatter formatter; nTime = formatter.FileTimeToJavaTime(nSetTime); nTime -= 9 \* 60 \* 60\* 1000; return nTime;
}
It use another class MyFormatter that I cannot understand. I really hate these stupid stuff !!! :mad: Does anyone have a simple way to get timestamp? Thank you in advance,
it due to what you want to. but for the code you provided, i think it will not work, although i didn't look it completely. for example, dateBox.GetTime( tmpTime ); may not retrieve the right time value you want, it due to how the funtion you implemented. btw, you can select CTime to work for you, but time_t, and there are many other time types available, like you used.
-
it due to what you want to. but for the code you provided, i think it will not work, although i didn't look it completely. for example, dateBox.GetTime( tmpTime ); may not retrieve the right time value you want, it due to how the funtion you implemented. btw, you can select CTime to work for you, but time_t, and there are many other time types available, like you used.
-
While it's not completely portable, have you tried:
SystemTimeToFileTime(&ST,&FT);
__int64 *nTime = (__int64 *) &FT;
return *nTime;
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
thank you, DavidCrow it works, and a little bit better. but I mean, here is the progress: from dialog item -> CTime variable -> another CTime var -> SYSTEMTIME var -> FILETIME var -> __int64 result well, I think it's too much. It's too complex for newbie in VC++, also. And the most is: is it really necessary to be like that??? Do you have a simplier solution for this? Does anyone have? thank you very much, :)
modified on Tuesday, July 1, 2008 1:17 AM
-
I think because there're many types, so it makes me confused. I just want to use the simple way, ;) And, dataBox.GetTime(tmpTime) works, I get the correct value I need
-
yes. i did say dataBox.GetTime(tmpTime) may not work, i used 'may', not 'must'. lol. it due to your implement, if you use its inner point, of course it work, right? lol
-
thank you, DavidCrow it works, and a little bit better. but I mean, here is the progress: from dialog item -> CTime variable -> another CTime var -> SYSTEMTIME var -> FILETIME var -> __int64 result well, I think it's too much. It's too complex for newbie in VC++, also. And the most is: is it really necessary to be like that??? Do you have a simplier solution for this? Does anyone have? thank you very much, :)
modified on Tuesday, July 1, 2008 1:17 AM
tataxin wrote:
Do you have a simplier solution for this?
Not by much. What about:
__int64 CMyDlg::getTimestamp( void )
{
SYSTEMTIME stDate;
m_date.GetTime(&stDate);SYSTEMTIME stTime; m\_time.GetTime(&stTime); stDate.wHour = stTime.wHour; stDate.wMinute = stTime.wMinute; stDate.wSecond = stTime.wSecond; FILETIME ft; SystemTimeToFileTime(&stDate, &ft); \_\_int64 \*nTime = (\_\_int64 \*) &ft; return \*nTime;
}
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
thank you, DavidCrow it works, and a little bit better. but I mean, here is the progress: from dialog item -> CTime variable -> another CTime var -> SYSTEMTIME var -> FILETIME var -> __int64 result well, I think it's too much. It's too complex for newbie in VC++, also. And the most is: is it really necessary to be like that??? Do you have a simplier solution for this? Does anyone have? thank you very much, :)
modified on Tuesday, July 1, 2008 1:17 AM
You're right. It's way too complex. The insane complexity started with MFC in the mid/late 1990s. I think Java became popular around then because people were disgusted with the complex crap from Microsoft. In response, Microsoft created a more sane platform, C# and .NET, copying a lot from Java. The simpler solution is to switch to C#. It's amazing how much simpler everything is in C#.
-
tataxin wrote:
Do you have a simplier solution for this?
Not by much. What about:
__int64 CMyDlg::getTimestamp( void )
{
SYSTEMTIME stDate;
m_date.GetTime(&stDate);SYSTEMTIME stTime; m\_time.GetTime(&stTime); stDate.wHour = stTime.wHour; stDate.wMinute = stTime.wMinute; stDate.wSecond = stTime.wSecond; FILETIME ft; SystemTimeToFileTime(&stDate, &ft); \_\_int64 \*nTime = (\_\_int64 \*) &ft; return \*nTime;
}
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
You're right. It's way too complex. The insane complexity started with MFC in the mid/late 1990s. I think Java became popular around then because people were disgusted with the complex crap from Microsoft. In response, Microsoft created a more sane platform, C# and .NET, copying a lot from Java. The simpler solution is to switch to C#. It's amazing how much simpler everything is in C#.
-
you're right, :) so i'm lucky because it works, even I don't know what is inner point, :(. I just let dataBox is the member of the dialog. can you show me the document about inner point so I can read about it. thank you, kcynic, ;)
dateBox.GetTime( tmpTime ); in this line, you might only want to retrieve a time value from your dialog. what i said inner point means in the tmpTime, if it isn't a CTime object, you should use points the new values and return, otherwise, you can't return the right value via tmpTime, right? especially, for c++ class, there are two copying ways: simple copy and deep copy. Almost every C++ book will refer it, you can look up it.
modified on Tuesday, July 1, 2008 11:11 PM