W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
#include
#include
using namespace std; int main() { struct tm date; time_t now; time_t before; // 获取当前时间戳 time(&now); // 获取5小时前的时间戳 date = *localtime(&now); date.tm_hour -= 5; before = mktime(&date); // 计算两个时间戳的差值(秒) cout << difftime(now, before); return 0; }