如何将 DateTime 转换为 MySQL 中的数字? [英] How to convert DateTime to a number in MySQL?

查看:44
本文介绍了如何将 DateTime 转换为 MySQL 中的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 MySQL 中的 DateTime 实例获取自 '1970-01-01 00:00:01' 以来的总秒数?

How can I get the total number of seconds since '1970-01-01 00:00:01' from a DateTime instance in MySQL?

推荐答案

你正在寻找 UNIX_TIMESTAMP().

参见:http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_unix-timestamp

如果使用日期参数调用 UNIX_TIMESTAMP(),它会返回参数的值作为自 '1970-01-01 00:00:00' UTC 以来的秒数.

If UNIX_TIMESTAMP() is called with a date argument, it returns the value of the argument as seconds since '1970-01-01 00:00:00' UTC.

这篇关于如何将 DateTime 转换为 MySQL 中的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆