获得未来的时间价值

时间:2010-12-08 23:42:28

标签: c++

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

using namespace std;

int main()
{
    time_t current = time(0);

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

如何从当前时间1小时后得到未来的时间?

1 个答案:

答案 0 :(得分:5)

time(2)返回自1970-01-01 00:00:00 +0000(UTC)以来的秒数。一小时后将是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";