开发者

get future time value

#include <time.h>
#include <iostream>

using namespace std;

int main()
{
    time_开发者_Python百科t current = time(0);

    cout << ctime(&current) << endl; 
    return 0;
}

How can I get the future time, say 1 hour later, from the current time?


time(2) returns the number of seconds since 1970-01-01 00:00:00 +0000 (UTC). One hour later would be current + 3600.

time_t current   = time(0);
time_t inOneHour = current + (60*60); // 60 minutes of 60 sec.

cout << "Now: " << ctime(&current) << "\n" 
     << "In 1 hour: " << ctime(&inOneHour)
     << "\n";
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜