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 the string 2011-12-21 02:20pm
which needs to be in Unix timestamp format.
推荐答案
UNIX_TIMESTAMP()
解决问题:
但是,UNIX_TIMESTAMP()
函数只采用标准 MySQL 格式的日期.如果要使用 AM/PM 表示法,则需要使用 STR_TO_DATE
首先像这样:
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:
这篇关于MySQL中时间戳的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!