开发者

How do I convert a time to tm struct instead of CTime class

I currently have code that creates a CTime object from a de开发者_StackOverflowfined value.

#define TIME_VALUE 0x301DDF00  // Aug 1, 1995 @ 04:00:00

CTime t = CTime( TIME_VALUE );

This creates the desired date of Aug 1, 1995 04:00:00

I can no longer use CTime so I am trying to use time_t and tm instead. Since the CTime constructor takes in the number of seconds since Jan 1, 1970 and time_t represents the number of seconds since Jan 1, 1970, I tried to use the following code.

#define TIME_VALUE 0x301DDF00  // Aug 1, 1995 @ 04:00:00

time_t tmpTime = TIME_VALUE;
struct tm createTime;

if( localtime_s( &createTime, &tmpTime ) == S_OK )
{ 
 // Use createTime
}

createTime ends up as August 1, 0095 04:00:00. How am I supposed to go from the defined value to a time_t and tm successfully?

Thanks in advance.


Sorry. I didn't look at the tm documentation closely enough. The year is the actual year minus 1900 and the month is zero based. I got it now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜