求教CTime的问题

C++语言 码拜 9年前 (2015-05-11) 1103次浏览 0个评论

我在程序里面写了这样一段话:

CTime time = GetCurrentTime();
	CString str = time.Format(_T("%Y_%m_%d %H:%M:%S"));
	MessageBox(NULL,str,"caution",MB_OK);
	CString sss = (time+CTimeSpan(0,0,0,10)).Format(_T("%Y_%m_%d %H:%M:%S"));
	MessageBox(NULL,sss,"caut",MB_OK);

在我的电脑上得到的两个时间差是10s,但是在另一台电脑上面却得到的两个时间差是2分多,一直很纳闷这个是不是电脑的问题,不知道怎么解决,貌似还有一个奇怪的问题,得到的当前时间是1970年左右(当然这个不是重点),求指教,

40分
CTime::GetCurrentTime()

GetCurrentTime()
不是一回事!

CTime::operator = 
const CTime& operator =( const CTime& timeSrc );

const CTime& operator =( time_t t );

Remarks

These overloaded assignment operators copy the source time into this CTime object. 

The internal time storage in a CTime object is independent of time zone. Time-zone conversion is not necessary during assignment.

Example

// example for CTime::operator =
time_t osBinaryTime;  // C run-time time (defined in <time.h>)
CTime t1 = osBinaryTime; // Assignment from time_t
CTime t2 = t1; // Assignment from CTime

CTime Overview |  Class Members |  Hierarchy Chart

See Also   CTime::CTime

引用 1 楼 zhao4zhong1 的回复:

CTime::GetCurrentTime()

GetCurrentTime()
不是一回事!

CTime::operator = 
const CTime& operator =( const CTime& timeSrc );

const CTime& operator =( time_t t );

Remarks

These overloaded assignment operators copy the source time into this CTime object. 

The internal time storage in a CTime object is independent of time zone. Time-zone conversion is not necessary during assignment.

Example

// example for CTime::operator =
time_t osBinaryTime;  // C run-time time (defined in <time.h>)
CTime t1 = osBinaryTime; // Assignment from time_t
CTime t2 = t1; // Assignment from CTime

CTime Overview |  Class Members |  Hierarchy Chart

See Also   CTime::CTime

恩,试了一下,就是这个原因,两者混淆了,谢谢


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求教CTime的问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!