51Testing软件测试论坛

标题: vugen函数帮助文档asctime中的例子打印的小时值不对 [打印本页]

作者: moon2599    时间: 2014-8-30 13:57
标题: vugen函数帮助文档asctime中的例子打印的小时值不对
下面代码拷贝自vugen函数帮助文档asctime中的例子,发现打印出的最终结果中小时的值是错误的。用ctime(&t)打印出来的时间才是正确的。是什么原因呢?

Action()
{
        typedef long time_t;

    struct tm {

        int tm_sec; // seconds after the minute - [0,59]

        int tm_min; // minutes after the hour - [0,59]

        int tm_hour; // hours since midnight - [0,23]

        int tm_mday; // day of the month - [1,31]

        int tm_mon; // months since January - [0,11]

        int tm_year; // years since 1900

        int tm_wday; // days since Sunday - [0,6]

        int tm_yday; // days since January 1 - [0,365]

        int tm_isdst; // daylight savings time flag

    #ifdef LINUX

        int tm_gmtoff;

        const char *tm_zone;

    #endif

    };

    time_t t;

    struct tm *gmt;

    time(&t); //Returns the system time.

    gmt = (struct tm *)gmtime(&t); //gmtime():Converts the system time into Coordinated Universal Time (UTC).

    lr_message ("Coordinated universal time:\t\t%s", asctime(gmt));
lr_message ("The systime is : %s",ctime(&t));

return 0;
}
打印结果如下:
Coordinated universal time:         Sat Aug 30 05:49:23 2014
The systime is : Sat Aug 30 13:49:23 2014




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2