加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – mktime和tm_isdst

发布时间:2020-12-16 05:43:18 所属栏目:百科 来源:网络整理
导读:我看到很多不同的意见,所以想到在这里问. 我读了man mktime: (A positive or zero value for tm_isdst causes mktime() to presume initially that summer time (for example,Daylight Saving Time) is or is not in effect for the specified time,respect
我看到很多不同的意见,所以想到在这里问.

我读了man mktime:

(A positive or zero value for tm_isdst causes mktime() to presume initially
 that summer time (for example,Daylight Saving Time) is or is not in
 effect for the specified time,respectively.  A negative value for
 tm_isdst causes the mktime() function to attempt to divine whether summer
 time is in effect for the specified time.

我的问题是,不应该将tm_isdst保持为-1,让系统决定其是否为dst,并且代码变得无关紧要?

我错过了什么吗?

解决方法

我相信原来的原因是一些时区没有夏令时.由于mktime不是同步安全的,也不是入门允许实现将当前夏令时的值存储在POSIX extern char tzname [2]中,由日光[0或1]索引.这意味着tzname [0] =“[std TZ name]”和tzname =“[日光TZ名称,例如EDT]”

有关详细信息,请参阅您的tzset()手册页.符合mktime()的标准要求表现得像tzset()一样.这种避免使用tm_isdst,IMO.

底线:您的特定实现和时区将决定是否对tm_isdst使用-1,0或1.所有实现都没有一种默认的正确方式.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读