为什么glibc的"时区"全球不与系统时间DST同意吗? [英] Why does glibc "timezone" global not agree with system time on DST?

查看:430
本文介绍了为什么glibc的"时区"全球不与系统时间DST同意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个奇怪的问题,在我的系统时钟都知道,它是夏令时,但glibc的似乎没有。这是一个上最新的Ubuntu安装,我已经检查的/ etc /本地时间,它有正确的转换时间为上周的切换到DST。

我目前正确的时区为太平洋夏令时(UTC-7)。当我问我的系统我在什么时间段,它告诉我正确的:

  $日期+%Z
-0700

但是当我运行下面的程序:

 的#include<&time.h中GT;
#包括LT&;&stdio.h中GT;诠释主(){
  tzset();
  的printf(%鲁\\ n,时区);
  返回0;
}

的输出,不正确:

  28800

而对应于UTC-8,或太平洋标准时间。 (不,TZ是不是在我的环境中设置)

我想的glibc和日期的程序将获得来自同一来源的时区信息,但显然他们要么不还是我误解如何glibc的时区的全球作品。

基本的问题是那么:


  1. 为什么是不同的这两个输出

  2. 如何可靠地检测系统UTC从C程序偏移?


解决方案

我不认为与夏令时时区的转变。尝试日光的变量。在我的系统:


      外部变量时区包含的差异,以秒为单位,
      UTC与当地标准时间之间(例如,在美国东部
      时区(EST),时区是5 * 60 * 60)。外部变量日光
      只有当一个夏天的时区调整是在指定非零
      TZ环境变量。

I'm experiencing a bizarre issue where my system clock knows that it's daylight savings time, but glibc seems not to. This is an up-to-date Ubuntu installation, and I have checked /etc/localtime and it has the correct changeover time for last week's switch to DST.

The current correct timezone for me is Pacific Daylight Time (UTC-7). When I ask my system what time zone I'm in, it tells me correctly:

$ date +%z
-0700

But when I run the following program:

#include <time.h>
#include <stdio.h>

int main() {
  tzset();
  printf("%lu\n", timezone);
  return 0;
}

The output is, incorrectly:

28800

Which corresponds to UTC-8, or Pacific Standard Time. (And no, TZ is not set in my environment)

I thought glibc and the date program would get their time zone information from the same source, but apparently either they don't or I'm misunderstanding how the glibc timezone global works.

The basic questions are then:

  1. Why are these two outputs different
  2. How can I reliably detect the system UTC offset from a C program?

解决方案

I don't think "timezone" changes with daylight time. Try the "daylight" variable. On my system:

      The external variable timezone contains the difference, in seconds,
      between UTC and local standard time (for example, in the U.S. Eastern
      time zone (EST), timezone is 5*60*60).  The external variable daylight
      is non-zero only if a summer time zone adjustment is specified in the
      TZ environment variable.

这篇关于为什么glibc的&QUOT;时区&QUOT;全球不与系统时间DST同意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆