MySQL中的UNIX_TIMESTAMP和NOW()的区别 [英] Difference between UNIX_TIMESTAMP and NOW() in MySQL
问题描述
NOW()
插入他们发表评论的时间,然后使用 date('j M Y',存储时间戳)
显示他们发布的时间。 我想知道NOW()返回最终用户的 locatime或我服务器上的本地时间
。
更适合使用 UNIX_TIMESTAMP
比 NOW()
计算用户发布的本地时间
函数 NOW()
时间字符串,由您的MySQL服务器的时区确定。
但是,使用 UNIX_TIMESTAMP()
,以GMT格式表示。这样做使得根据访问者的国家(例如使用JavaScript)更容易格式化。
如果您仍然想使用 DATETIME
列,您可以使用 UTC_TIMESTAMP()
存储时间(它格式化日期,如 NOW()
但表示在UTC);它应该在所有其他方面或多或少地相同。
I have a blog where users can comment. I insert the time at which they posted a comment using NOW()
and then use date('j M Y', stored timestamp)
to show the time at which they posted.
I want to know does NOW() return the locatime of the end user or the localtime at my server
.
Is it better suited to use UNIX_TIMESTAMP
than NOW()
to calculate the localtime at which users posted a comment.
The function NOW()
generates a formatted date-time string, determined by the time zone of your MySQL server.
However, it would be better to store times using UNIX_TIMESTAMP()
, which is expressed in GMT. Doing so makes it easier to format it according to the country of a visitor (e.g. using JavaScript).
If you still want to use DATETIME
columns, you can store times using UTC_TIMESTAMP()
(it formats a date like NOW()
but expresses it in UTC); it should more or less work the same in all other aspects.
这篇关于MySQL中的UNIX_TIMESTAMP和NOW()的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!