首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

Linux上,通过C++修改系统时间

2012-12-23 
Linux下,通过C++修改系统时间源码如下:#include iostream#include sys/time.husing namespace stdint

Linux下,通过C++修改系统时间
源码如下:

#include <iostream>#include <sys/time.h>using namespace std;int main() {timeval p;gettimeofday(&p, NULL);printf("currentTime:%d\n", (int)p.tv_sec);p.tv_sec = p.tv_sec + 60 * 5;    //系统时间增加五分钟settimeofday(&p, NULL);gettimeofday(&p, NULL);printf("currentTime:%d\n", (int)p.tv_sec);return 0;}


在编译成功并执行程序之后,查看系统时间,时间会增加五分钟。

热点排行