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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Why does subtracting these two times give a strange result? (2011)

41 点作者 gs7超过 11 年前

8 条评论

geuis超过 11 年前
Of all things that are troublesome when it comes to building software products, time is the hydra that keeps raising a head over and over. I&#x27;ve lost count of the gotchas that come with the question of &quot;what time is it?&quot;.<p>In complete seriousness, I hope a time comes eventually where cosmology has advanced to a point where we have a measurement of current time relative to the Big Bang accurate to the nano second. Given issues of relativity and such, it would be a value only local to us, but that&#x27;s more than fine. When we start hashing out time values with aliens, that will be a different problem.
评论 #6663007 未加载
kbenson超过 11 年前
This is why you always normalize your timestamps to UTC for storage&#x2F;logging. To explain in a bit more detail, here&#x27;s a thought experiment. You are in California, and it&#x27;s 2012-11-04 1:30 AM. You need to save this time to refer to it later (pick your favorite reason).<p>If you assume you are storing times in your time zone, why can&#x27;t you determine the correct time the timestamp refers to at a later date?<p>Why is your location important?
评论 #6662694 未加载
apaprocki超过 11 年前
There&#x27;s much more simpler (and relevant) ways to break date logic than going back to 1927. Take for instance:<p><pre><code> var d = new Date(2013, 9, 20); </code></pre> For 200 million people in the world, d.getDate() will be 19.<p>Now, are you sure your app doesn&#x27;t break when that happens?
评论 #6662012 未加载
stygiansonic超过 11 年前
I&#x27;ve always loved date-time problems because it&#x27;s one of those things that seems straightforward and simple, but when you drill down into it, turns out to be devilishly hard. It&#x27;s made me think twice anytime I want to jump to the conclusion that something is &quot;simple&quot;.
评论 #6662447 未加载
MichaelGG超过 11 年前
It seems wrong, or VB-ish, to assume the local system settings for things such as parsing. Shouldn&#x27;t the default be to use UTC, and then force developers to opt-in to &quot;whatever the user currently has&quot;? Or at force parseUtc or parseLocal? I understand that there&#x27;s an argument for doing what the programmer probably has in mind, but in too many cases, the programmer hasn&#x27;t even thought of that.<p>The fact you could run this, take a flight somewhere, run it again and get totally different results seems unsettling. (Same thing applies to numeric parsing&#x2F;display functions.)<p>I ran into one customer having problems authenticating to our service; turns out his clocks were on local time, not UTC. He seemed upset about that, until I pointed out that his billing records will get an extra hour, or go negative, during DST transitions. Changed his tune pretty quickly.<p>Another customer handled it a different way: &quot;Oh, the platform we use crashes when a time transition occurs, so we never generate records spanning such times.&quot;
bgdam超过 11 年前
Shameless plug: If your webapp deals with date, time and timezones in the past, present or future, you may want to use TimeNinja[0] - a simple, free REST API, I built, for date time conversion and arithmetic which uses historical timezone information to perform required calculations.<p>[0] <a href="http://www.timeninja.net" rel="nofollow">http:&#x2F;&#x2F;www.timeninja.net</a>
prezjordan超过 11 年前
I feel like the perseon who answered this question is the same person who asked it. How could anyone stumble across this error?
评论 #6662409 未加载
评论 #6662464 未加载
评论 #6662418 未加载
评论 #6662350 未加载
bladedtoys超过 11 年前
Meta answer: because we still use a calendar that was designed to track Roman feast days.