Linux 修改系统时间 需要Root权限
2016-03-27 16:44
477 查看
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
void setSystemTime(long timep)
{
struct timeval tv;
tv.tv_sec = (time_t)timep;
tv.tv_usec = 0;
if(settimeofday (&tv, (struct timezone *) 0) < 0)
{
printf("Set system datatime error!/n");
//return -1;
}
}
void main()
{
long date = 1459157400L;
time_t time_p;
struct tm * tmp_tm;
time(&time_p);
tmp_tm = localtime(&time_p);
printf("time1=%s\n",asctime(tmp_tm));
setSystemTime(date);
time(&time_p);
tmp_tm = localtime(&time_p);
printf("time2=%s\n",asctime(tmp_tm));
printf("end of main\n");
}
#include <unistd.h>
#include <stdio.h>
void setSystemTime(long timep)
{
struct timeval tv;
tv.tv_sec = (time_t)timep;
tv.tv_usec = 0;
if(settimeofday (&tv, (struct timezone *) 0) < 0)
{
printf("Set system datatime error!/n");
//return -1;
}
}
void main()
{
long date = 1459157400L;
time_t time_p;
struct tm * tmp_tm;
time(&time_p);
tmp_tm = localtime(&time_p);
printf("time1=%s\n",asctime(tmp_tm));
setSystemTime(date);
time(&time_p);
tmp_tm = localtime(&time_p);
printf("time2=%s\n",asctime(tmp_tm));
printf("end of main\n");
}
相关文章推荐
- linux内核设计与实现一书阅读整理 之第十八章
- Linux第五周学习总结——扒开系统调用的三层皮(下
- 《Linux内核设计与实现》第十八章读书笔记
- Linux系统下JavaJDK,Eclipse,Androrid studio的安装教程
- linux定时任务生产java服务无法执行问题
- 【7】Linux-内核链表
- 报错storage size of ‘act’ isn’t known当使用std=c99编译struct sigaction
- Linux内核分析— —扒开系统调用的三层皮(下)
- 实现VMware Workstation中的CentOS 6.6 上网的方法
- 第五周linux学习笔记
- 《Linux内核设计与实现》第5章读书整理
- Linux内核分析-系统中断在内核中的实现
- Linux Web服务器网站故障分析常用的命令
- Linux内核分析-分析system_call中断处理过程
- 为VirtualBox里的Linux系统安装增强功能
- linux内核设计与实现一书阅读整理 之第五章
- Linux基础--系统启动流程
- 给linux移植Ethercat笔记
- 《Linux内核分析》-- 扒开系统调用的三层皮(下)之system_call中断处理过程 20135311傅冬菁
- Linux C目标文件