Unix在内部是否存储GMT时间偏移量? 喜欢例如:印度标准时间是格林尼治标准时间+5:30.是这5:30存储一些地方?格林威治标准时间偏移
我需要这样使用它在脚本中像下面
if[[ off is "some value"]]
then
some statements
fi
Unix在内部是否存储GMT时间偏移量? 喜欢例如:印度标准时间是格林尼治标准时间+5:30.是这5:30存储一些地方?格林威治标准时间偏移
我需要这样使用它在脚本中像下面
if[[ off is "some value"]]
then
some statements
fi
下面的程序打印“-04:00”我在美国东部时间并打印'04:30' 当我设置TZ为‘亚洲/加尔各答’:
#include <stdio.h>
#include <time.h>
int
main()
{
int hours;
int minutes;
int negative_sign = 1;
tzset();
// printf ("tzname: %s tzname[1]: %s\n", tzname [0], tzname [1]);
// printf ("DST: %d\n", daylight); /* 0 when no DST */
// printf ("timezone: %ld\n", timezone);
/* 'timezone' is the number of seconds west of GMT */
/* It is negative for tzs east of GMT */
if (timezone <= 0) {
timezone = -timezone;
negative_sign = 0;
}
if (daylight) {
timezone -= 3600; /* substract 1h when DST is active */
if (timezone <= 0) {
timezone = -timezone;
negative_sign = 0;
}
}
timezone /= 60; /* convert to minutes */
hours = timezone/60;
minutes = timezone % 60;
printf ("%s%02d:%02d\n", (negative_sign ? "-" : ""), hours, minutes);
return 0;
}
随意使用/修改任何你想要的,然后从你的shell脚本中调用它。
内核保持GMT时间内,当问及对本地时间计算使用的时区信息的偏移。这样,如果需要更改时区,则内部不需要更改时钟。
传统上,在UNIX中,内核保持当前时间为独立于时区的形式,这是它向应用程序报告的内容。
应用程序查询环境变量和/或用户配置(对于不同的用户或一个用户的不同会话可以是不同的),以确定哪个时区报告时间。为此,保存系统知道的所有时区的偏移量(这些表格需要不断更新,才能对夏时制算法进行政治更改)。
在内核或驱动程序中,没有。
通常,它存储在一个名为/ etc/localtime的文件中。该文件通常是指向其他地方的文件的链接,该文件包含用于将GMT转换为本地时间的所有“规则”(包括压缩形式),包括夏令时开始和结束时,与GMT的偏移量等等。
它可以被'TZ'环境变量覆盖。 – ephemient 2009-12-09 03:52:46
是的......如果你问一个*特定的问题,你甚至可以学习如何做一些有用的事情! :) – hobbs 2009-12-09 03:38:19