mysql中要时间戳的字符串 [英] String to timestamp in mysql
本文介绍了mysql中要时间戳的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以在MySQL中将字符串转换为UNIX时间戳吗?
Is there any way to convert string to UNIX timestamp in MySQL?
例如,我有字符串2011-12-21 02:20pm
,该字符串必须为unix时间戳格式.
For example I have string 2011-12-21 02:20pm
which needs to be in unix timestamp format.
推荐答案
UNIX_TIMESTAMP()
可以解决问题:
SELECT UNIX_TIMESTAMP('2011-12-21 14:20:00');
但是,UNIX_TIMESTAMP()
函数仅采用标准的MySQL格式化日期.如果要使用AM/PM表示法,则需要使用
However, the UNIX_TIMESTAMP()
function only takes a standard MySQL formatted date. If you want to use the AM/PM notation, you will need to use STR_TO_DATE
first like this:
SELECT UNIX_TIMESTAMP(
STR_TO_DATE('2011-12-21 02:20pm', '%Y-%m-%d %h:%i%p')
);
这篇关于mysql中要时间戳的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文