TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Modernized time.h for ISO C (1998)

61 点作者 mr_tyzic超过 10 年前

7 条评论

Dylan16807超过 10 年前
Why does TAI start with an offset of 10 seconds? 1972-01-01 is before any leap seconds.<p>Edit: I can see it matches the right value but I can&#x27;t figure out why. There have been 25 leap seconds but there&#x27;s a 35 second offset...<p>Edit 2: Apparently the clocks ran at <i>different speeds</i> for a decade, and the difference got rounded to 10 in 1972.
评论 #8411990 未加载
cremno超过 10 年前
`struct xtime` and `xtime_get` were added in C11 as `struct timespec` and `timespec_get`:<p><a href="http://port70.net/~nsz/c/c11/n1570.html#7.27.1p3" rel="nofollow">http:&#x2F;&#x2F;port70.net&#x2F;~nsz&#x2F;c&#x2F;c11&#x2F;n1570.html#7.27.1p3</a><p><a href="http://port70.net/~nsz/c/c11/n1570.html#7.27.2.5" rel="nofollow">http:&#x2F;&#x2F;port70.net&#x2F;~nsz&#x2F;c&#x2F;c11&#x2F;n1570.html#7.27.2.5</a><p>There are some differences though. Not only the name and types differ. But also `timespec_get` is only required to support `TIME_UTC` and the specification is not as detailed.
评论 #8410735 未加载
TeMPOraL超过 10 年前
As a reminder of how painful and complicated dealing with time is, here is an excellent essay by Erik Naggum:<p><a href="http://naggum.no/lugm-time.html" rel="nofollow">http:&#x2F;&#x2F;naggum.no&#x2F;lugm-time.html</a>
评论 #8410669 未加载
评论 #8410643 未加载
wyc超过 10 年前
Not about C, but IMO the way that Go handles time is very convenient. Time zones are pretty well-encapsulated in the Time struct and that makes for really nice function interfaces. Also, there&#x27;s this gem:<p>` These three considerations—choose an epoch as early as possible, that uses a year equal to 1 mod 400, and that is no more than 2^63 seconds earlier than 1970—bring us to the year -292277022399. We refer to this year as the absolute zero year, and to times measured as a uint64 seconds since this year as absolute times. `<p><a href="https://golang.org/src/pkg/time/time.go" rel="nofollow">https:&#x2F;&#x2F;golang.org&#x2F;src&#x2F;pkg&#x2F;time&#x2F;time.go</a>
评论 #8410578 未加载
评论 #8412264 未加载
DonHopkins超过 10 年前
Summary of article: It&#x27;s about fucking &lt;time.h&gt;!
lysium超过 10 年前
So, is this still a draft?
user_id3超过 10 年前
haha, no.