简体   繁体   English

将文本时间戳转换为日期

[英]Convert text timestamp to date

I have a time stamp of the form 1518427677000 in a MySQL database. 我在MySQL数据库中有一个1518427677000形式的时间戳。 The type of the field in the database is TEXT. 数据库中字段的类型为TEXT。 I would like to convert this value to DATETIME in MySQL Query. 我想将此值转换为MySQL Query中的DATETIME。

I tried with CAST, CONVERT, STR_TO_DATE, date_format, FROM_UNIXTIME and UNIX_TIMESTAMP but all these functions return either an error or null. 我尝试使用CAST,CONVERT,STR_TO_DATE,date_format,FROM_UNIXTIME和UNIX_TIMESTAMP,但是所有这些函数都返回错误或null。

1518427677000 looks like UNIX Epoch... in milliseconds. 1518427677000看起来像UNIX Epoch ...,以毫秒为单位。 Just divide it by 1000: 只需将其除以1000:

SELECT FROM_UNIXTIME('1518427677000' / 1000)
-- 2018-02-12 14:27:57

It seems your timestamp is in milliseconds. 看来您的时间戳以毫秒为单位。 User FROM_UNIXTIME after dividing by 1000: 用户FROM_UNIXTIME除以1000后:

SELECT FROM_UNIXTIME (1518427677)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM