Linux时区文件基本信息解析

使用"file /usr/share/zoneinfo/PRC"查看时区文件产生的输出信息:

/usr/share/zoneinfo/PRC: timezone data, version 2, 3 gmt time flags, 3 std time flags, no leap seconds, 27 transition times, 3 abbreviation chars

使用二进制查看工具打开时区文件,对应的关键信息:

00000000: 545a 6966 3200 0000 0000 0000 0000 0000  TZif2...........
00000010: 0000 0000 0000 0003 0000 0003 0000 0000  ................
00000020: 0000 001b 0000 0003 0000 000c 8000 0000  ................
00000030: c859 5e80 c909 f970 c9d3 bd00 cb05 8af0  .Y^....p........
00000040: cb7c 4000 d23b 3ef0 d38b 7b80 d442 adf0  .|@..;>...{..B..
00000050: d545 2200 d64c bff0 d73c bf00 d806 6670  .E"..L...<....fp
00000060: d91d f280 d941 7cf0 1eba 5220 1f69 9b90  .....A|...R .i..
00000070: 207e 84a0 2149 7d90 2267 a120 2329 5f90   ~..!I}."g. #)_.
00000080: 2447 8320 2512 7c10 2627 6520 26f2 5e10  $G. %.|.&'e &.^.
00000090: 2807 4720 28d2 4010 0201 0201 0201 0201  (.G (.@.........
000000a0: 0201 0201 0201 0201 0201 0201 0201 0201  ................
000000b0: 0201 0200 0071 d700 0000 007e 9001 0400  .....q.....~....
000000c0: 0070 8000 084c 4d54 0043 4454 0043 5354  .p...LMT.CDT.CST
000000d0: 0000 0000 0000 0054 5a69 6632 0000 0000  .......TZif2....

1. 基本的头信息

545a 6966 - TZif
32 - version
00 0000 0000 0000 0000 0000 0000 0000 - reserve 15 bytes
0000 0003 - tzh_ttisgmtcnt
0000 0003 - tzh_ttisstdcnt
0000 0000 - tzh_leapcnt
0000 001b - tzh_timecnt
0000 0003 - tzh_typecnt
0000 000c - tzh_charcnt //The number of bytes of timezone abbreviation strings stored in the file.

2. tzh_timecnt four-byte  signed  integer  values  sorted  in  ascending order.

00000020: .... .... .... .... .... .... 8000 0000  ................
00000030: c859 5e80 c909 f970 c9d3 bd00 cb05 8af0  .Y^....p........
00000040: cb7c 4000 d23b 3ef0 d38b 7b80 d442 adf0  .|@..;>...{..B..
00000050: d545 2200 d64c bff0 d73c bf00 d806 6670  .E"..L...<....fp
00000060: d91d f280 d941 7cf0 1eba 5220 1f69 9b90  .....A|...R .i..
00000070: 207e 84a0 2149 7d90 2267 a120 2329 5f90   ~..!I}."g. #)_.
00000080: 2447 8320 2512 7c10 2627 6520 26f2 5e10  $G. %.|.&'e &.^.
00000090: 2807 4720 28d2 4010

3. tzh_timecnt one-byte unsigned integer values;

    each one tells which of the different types of local time types described in the file is associated with the time period starting with the same-indexed transition time.

00000090: .... .... .... .... 0201 0201 0201 0201  (.G (.@.........
000000a0: 0201 0201 0201 0201 0201 0201 0201 0201  ................
000000b0: 0201 02

4. tzh_typecnt ttinfo entries, each defined as follows:
    struct ttinfo {
       int32_t       tt_gmtoff;
       unsigned char tt_isdst;
       unsigned char tt_abbrind; //serves as an  index into the array of timezone abbreviation bytes that follow the ttinfo structure(s) in the file.
    };

000000b0: .... ..00 0071 d700 0000 007e 9001 0400  .....q.....~....
000000c0: 0070 8000 08

5. tzh_charcnt bytes of timezone abbreviation strings stored in the file.
CST - China Standard Time(中国标准时),tt_gmtoff = 0x7080 = 8 hours
CDT - China Daylight Time(中国夏令时),tt_gmtoff = 0x7e90 = 9 hours
LMT - Local Mean Time(本地平均时), tt_gmtoff = 0x71d7 = 8 hours M minutes N seconds (未使用)

000000c0: .... .... ..4c 4d54 0043 4454 0043 5354  .p...LMT.CDT.CST
000000d0: 00

6. tzh_leapcnt pairs of four-byte values, written in network byte order;

   tzh_ttisstdcnt standard/wall indicators, each stored as a one- byte boolean;

   tzh_ttisutcnt UT/local indicators, each stored as a one-byte boolean;

000000d0: ..00 0000 0000 00

参考:

1. https://www.man7.org/linux/man-pages/man5/tzfile.5.html

2. https://tools.ietf.org/html/rfc8536

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值