c – mktime和tm_isdst

我看到很多不同的意见,所以想到在这里问.

我读了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.所有实现都没有一种认的正确方式.

相关文章

对象的传值与返回说起函数,就不免要谈谈函数的参数和返回值...
从实现装饰者模式中思考C++指针和引用的选择最近在看...
关于vtordisp知多少?我相信不少人看到这篇文章,多半是来自...
那些陌生的C++关键字学过程序语言的人相信对关键字并...
命令行下的树形打印最近在处理代码分析问题时,需要将代码的...
虚函数与虚继承寻踪封装、继承、多态是面向对象语言的三大特...