mktime和tm_isdst的 [英] mktime and tm_isdst

查看:472
本文介绍了mktime和tm_isdst的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I saw a lot of different views so thought of asking here.

我读男人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还是不和的方式code成为DST无关?

My question is, shouldn't tm_isdst be kept as -1 to let the system decide if its dst or not and that way the code becomes dst agnostic?

我缺少的东西吗?

推荐答案

我相信原来的原因是一些时区没有夏令时。因为mktime不是异步安全也不是重入允许实施夏令的当前值存储在POSIX的extern炭TZNAME [2],由日光索引[0或1]。这意味着TZNAME [0] =[标准TZ名]和TZNAME =[日光TZ名称,例如EDT]

I believe the original reason for that is some timezones do not have daylight savings time. Since mktime is not async-safe nor is it re-entrant allows the implementation to store the current value of daylight savings in the POSIX extern char tzname[2], indexed by daylight [0 or 1]. This means tzname[0]="[std TZ name]" and tzname="[daylight TZ name, e.g. EDT]"

请参阅您的tzset()手册页以获取更多信息。符合mktime标准()来运行,就好像叫tzset()反正。种这避免了使用tm_isdst的的,海事组织。

See your tzset() man page for more information on this. Standards conforming mktime() is required to behave as though it called tzset() anyway. This kind of obviates the use of tm_isdst, IMO.

底线:你具体的实施和时区(S)将决定你是否会使用tm_isdst的-1,0或1。没有为所有实现无人默认的正确途径。

Bottom line: your particular implementation and timezone(s) would dictate whether you would use -1, 0, or 1 for tm_isdst. There is no one default correct way for all implementations.

这篇关于mktime和tm_isdst的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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