开发者

Getting the Current Time from the SystemTime using MFC

I want to get the开发者_StackOverflow中文版 time at UTC or GMT with respect to the current System Time in MFC. I have tried with the GetGmtTm() of the CTime as below

struct tm* osTime=NULL;   
tm t1 = *(currenttime.GetGmtTm( osTime ));
CTime currentUTCTime(1900+t1.tm_year, t1.tm_mon+1, t1.tm_mday, t1.tm_hour, t1.tm_min, t1.tm_sec, t1.tm_isdst);
CTimeSpan ts = currentUTCTime - oldtime;  //oldtime points to Unix Epoch 1/1/1970 00:00:00
unsigned long time = ts.GetTotalSeconds( );//to get the Unix time

But it is not working properly as expected. For some timezones like (GMT+6.00) Astana, Dhaka its getting the UTC time with a diff of 12hrs.

Can anyone help me to get a solution?

Thanks a lots in Advance :)


CTime::GetTime() returns the unixtime - this is always expressed as seconds since the epoch(which is defined as UTC/GMT time).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜