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
# 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) |