linux嵌入式系统修改时区
一. 网址参考
二. 实践
1. 对/etc/localtime修改软链接,命令如下:
//1. 先判断/etc/localtime是否存在,如果存在,则先删除 if (access("/etc/localtime", F_OK) == 0) ret = unlink("/etc/localtime"); //2. 重新创建软链接 ret = symlink("/usr/share/zoneinfo/posix/Etc/GMT-8", "/etc/localtime"); //注意:其GMT-8对应于GMT+8(东八区)
2. 注意:当时区设置为GMT+8(东八区), 用posix/Etc方式需要把软链接设置为GMT-8,刚好相反;表格如下:
1 typedef struct _sdmp_tz_list { 2 char *display; 3 char *actual; 4 }sdmp_tz_list_t; 5 6 static sdmp_tz_list_t tz_list[] = { 7 {"GMT-12", "GMT+12"}, {"GMT-11", "GMT+11"}, {"GMT-10", "GMT+10"}, 8 {"GMT-9", "GMT+9"}, {"GMT-8", "GMT+8"}, {"GMT-7", "GMT+7"}, 9 {"GMT-6", "GMT+6"}, {"GMT-5", "GMT+5"}, {"GMT-4", "GMT+4"}, 10 {"GMT-3", "GMT+3"}, {"GMT-2", "GMT+2"}, {"GMT-1", "GMT+1"}, 11 {"GMT-0", "GMT+0"}, {"GMT+0", "GMT-0"}, {"GMT+1", "GMT-1"}, 12 {"GMT+2", "GMT-2"}, {"GMT+3", "GMT-3"}, {"GMT+4", "GMT-4"}, 13 {"GMT+5", "GMT-5"}, {"GMT+6", "GMT-6"}, {"GMT+7", "GMT-7"}, 14 {"GMT+8", "GMT-8"}, {"GMT+9", "GMT-9"}, {"GMT+10", "GMT-10"}, 15 {"GMT+11", "GMT-11"}, {"GMT+12", "GMT-12"} 16 };