开发者

get future time value

开发者 https://www.devze.com 2023-01-29 08:21 出处:网络
#include <time.h> #include <iostream> using namespace std; int main() { time_开发者_Python百科t current = time(0);
#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

精彩评论

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