我可以使用struct tm和time(),localtime(),asctime()获取系统时间,但是我需要关于如何使用c程序设置系统时间的帮助。使用c库函数的系统时间设置
2
A
回答
4
,如果你不希望执行shell命令即可(如你所提到的)使用settimeofday,我会通过阅读MAN page,或找一些例子
这里开始是一个例子:
#include <sys/time.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char *argv[])
{
struct timeval now;
int rc;
now.tv_sec=866208142;
now.tv_usec=290944;
rc=settimeofday(&now, NULL);
if(rc==0) {
printf("settimeofday() successful.\n");
}
else {
printf("settimeofday() failed, "
"errno = %d\n",errno);
return -1;
}
return 0;
}
无耻扯下从IBMs documentation,该struct timeval
结构持有秒钟,UTC 00:00:00(Unix纪元时间)1970年1月1日号(作为long
)加微秒数(作为long
)。所以你需要计算这些数字来设定时间。你可以使用这些helper functions,以更好地处理与timeval结构的处理。
相关问题
- 1. 设置系统时间c#不工作
- 2. 使用C#.NET设置系统时间而不使用kernel32.dll
- 3. 在Windows 7上使用C#设置系统时间
- 4. 在C库函数中调用系统
- 5. 设置系统日期,同时保持系统时间使用PowerShell
- 6. Node.js - 设置系统日期/时间
- 7. 设置系统时间与在Linux中
- 8. 系统时间设置通知
- 9. 如何设置系统时间?
- 10. 使用junitPlatform时设置系统属性
- 11. C时间函数是否依赖于系统时钟?
- 12. 在GPIO上使用GPS PPS在GPS上设置系统时间
- 13. Datagridview日期时间格式不使用系统区域设置
- 14. 如何设置bundler config在必要时使用系统库
- 15. 以C#获取并设置系统时间
- 16. 使用Objective-C设置系统偏好设置
- 17. 运输时间表系统的数据库设计
- 18. 无偏时间系统C#
- 19. 更新系统时间C
- 20. 通过比较使用后台服务的系统时间与数据库值的系统时间的通知
- 21. 实时系统数据库使用
- 22. 如何使AppleScript更改系统偏好设置中的时间
- 23. 使用php系统函数
- 24. 从C调用操作系统设置#
- 25. 如何设置系统属性用C
- 26. 系统状态函数C#
- 27. 系统设置?
- 28. TimePickerDialog根据设备的时间系统设置格式
- 29. C#禁用系统时间更改
- 30. Windows 10使用CMD的系统设置
什么操作系统? – 2010-05-26 19:40:48
linux操作系统。 – neo730 2010-05-27 05:24:18