Chinaunix首页 | 论坛 | 博客
  • 博客访问: 549403
  • 博文数量: 116
  • 博客积分: 2063
  • 博客等级: 大尉
  • 技术积分: 1174
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-26 16:44
个人简介

none

文章分类

全部博文(116)

文章存档

2023年(2)

2020年(3)

2019年(4)

2018年(7)

2017年(6)

2016年(17)

2015年(13)

2014年(19)

2013年(6)

2012年(13)

2011年(5)

2010年(11)

2008年(10)

分类: LINUX

2012-06-02 10:29:51

Why does localtime() return times in UTC even when I have my timezone set?

The uClibc time functions get timezone information from the TZ environment variable, as described in the Single Unix Specification Version 3. See for details on valid settings of TZ. For some additional examples, read in the uClibc mailing list archive. You can store the value of TZ in the file '/etc/TZ' and uClibc will then automagically use the specified setting.


You need to be sure the TZ environment variable is set properly,
since uClibc does not support /etc/zoneinfo junk.
See 'man 3 tzset' or read the SuSv3 docs at
  
for details on how to set TZ for localtime.

For example, here is date with glibc:
    $ date
    Thu Aug  1 14:31:58 MDT 2002

Here is date with uClibc, when the TZ environment variable is set:

    $ TZ=MDT6 ./busybox date
    Thu Aug  1 14:34:53 MDT 2002

This means that MST (Mountain Daylight Time) is 6 hours earlier
than Coordinated Universal Time (UTC) and does not have daylight
saving time.

Here is another simple example:

    $ TZ=JST-9 ./busybox date
    Fri Aug  2 05:40:45 JST 2002

This means that Japanese Standard Time (JST) is 9 hours earlier
than Coordinated Universal Time (UTC) and does not have daylight
saving time.


Here is a more complex example:

    $ TZ=MST7MDT ./busybox date
    Thu Aug  1 14:32:04 MDT 2002

This means that Mountain Standard Time (MST) is 7 hours earlier
than Coordinated Universal Time (UTC).  Both standard time and
daylight saving time apply to this locale.  By default Mountain
Daylight Time (MDT) is one hour ahead of MST.  Since it isn't
otherwise specified, daylight saving time starts on the first
Sunday of April at 2:00 A.M. and ends on the last Sunday of
October at 2:00 A.M.

Here is an even uglier example:

    $ TZ=NST3:30NDT1:30 ./busybox date
    Thu Aug  1 19:13:03 NDT 2002

This means that Newfoundland Standard Time (NST) is 3.5 hours
earlier than Coordinated Universal Time (UTC).  Both standard
time and daylight saving time apply to this locale.  Newfoundland
Daylight Time is 1.5 hours earlier than Coordinated Universal
Time (UTC).
 
Normally, one would set TZ in /etc/profile.

TEST ON MY DEVICE
# cat /etc/TZ 
CST-8
# busybox | head -1
BusyBox v1.19.2 (2011-12-10 10:19:37 CST) multi-call binary.

echo `date` > /tmp/test
echo `date -u` >> /tmp/test
echo `date +%m:%d:%H` >> /tmp/test

# cat /tmp/test 
Sat Jun 2 09:48:13  CST  2012
Sat Jun 2 09:48:13 UTC 2012
06:02:17
阅读(2863) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~