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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: Timestamp vs. millis, storing time in database

2 点作者 govindpatel将近 9 年前
Ok. this question usually come to my mind and always I prefer using millis because I think that is the easiest way to store and get the time in database.<p>But some of my friends prefer using timestamp.<p>So I just wanted to know, What is the best practise for storing time in database ?<p>When choosing between timestamp and millis which one you prefer using and why?

1 comment

gjvc将近 9 年前
We have a very similar problem. We keep timestamps in numeric form as &quot;epoch nanos&quot; (nanoseconds from 1970-01-01 00:00) We are using PostgreSQL as the database, and I would very much like to use the native type (TIMESTAMP) [1], but PostgreSQL only keeps TIMESTAMP columns to microseconds, not nanoseconds. :-(<p>Using the native DBMS types allows use of native DBMS time and interval functionality, unless you like doing it yourself.<p>See also [2]<p>[1] <a href="https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;9.6&#x2F;static&#x2F;datatype-datetime.html" rel="nofollow">https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;9.6&#x2F;static&#x2F;datatype-datetime...</a><p>[2] <a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;409286&#x2F;should-i-use-field-datetime-or-timestamp" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;409286&#x2F;should-i-use-field...</a>
评论 #12049183 未加载