blog.TangGaowei.com

VS2005 C++ 中自己构造时间

作者 传说一梦 写于 2008-05-08  | 458 次浏览

#include <windows.h>
#include <afxwin.h>
#include <atltime.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

int _tmain(int argc, _TCHAR* argv[])
{
    char           buff[80];
    __time64_t result;

    // 构造 2008年4月28日 22:18:39 的时间
    CTime        t(2008,4,28,22,18,39);

    CString s = t.Format( _T("%A, %B %d, %Y") );

    struct tm when;
    t.GetLocalTm(&when);

    // 在自定义的时间上,再加 8 小时
    // 即变为 2008年4月29日 6:18:39
    when.tm_hour = when.tm_hour + 8; 

    // 重构时间,并输出显示
    if( (result = mktime( &when )) != (time_t)-1 )
    {
        asctime_s( buff, sizeof(buff), &when );
        printf( "the time will be %s\n", buff );
    }
    else
    {
        printf( "mktime failed" );
    }
}

[ 标签: 时间处理 ]
[ 固定链接:http://blog.tanggaowei.com/2008/05/vs2005-c-3.html ]

订阅

 

手机访问

http://blog.tanggaowei.com/wap/

Google