题
的Unix是否存储来自GMT的偏移的机器的内部? 像例如:印度标准时间为GMT + 5:30.is此5:30存储一些其中
?我需要此使用它在脚本中像下面
if[[ off is "some value"]]
then
some statements
fi
解决方案
下面的程序打印 '-04:00' 在EDT我和打印'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脚本中调用它。
其他提示
传统上,在UNIX中,内核保持当前时间的时区无关的形式,这是它报告给应用程序。
应用协商环境变量和/或用户配置(其可以是针对不同的用户或不同的会话为一个用户不同),以确定在报告的时间哪个时区。为了这个目的,有表保持在磁盘上,其保持系统知道关于所有时区的偏移量(这些表需要为政治变化到日光节约算法被连续地更新)。
内核保持GMT时间内,当问及对本地时间计算使用的时区信息的偏移。这样,如果需要时区变化,在内部,时钟不需要变化。
在内核或驱动器,无
通常,它是存储在一个名为/ etc /本地时间的文件。该文件通常是在别处,它包含(以压缩形式),用于GMT转换为本地时间,当夏令时的开始和结束,包括从GMT的偏移,等等所有的“规则”的文件的链接。
不隶属于 StackOverflow