MySQL UNIX_TIMESTAMP(now())-当前时间(以毫秒为单位) [英] MySQL UNIX_TIMESTAMP(now()) - current time in milliseconds

查看:1208
本文介绍了MySQL UNIX_TIMESTAMP(now())-当前时间(以毫秒为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种MySQL方法可基于当前MySQL时间(以毫秒为单位)进行查询?

Is there a MySQL way to query based on current MySQL time in milliseconds?

我正在尝试:

选择now_in_mili中的UNIX_TIMESTAMP(),UNIX_TIMESTAMP(NOW())

SELECT UNIX_TIMESTAMP(), UNIX_TIMESTAMP(NOW()) as now_in_mili

但是两列返回的都是相同的(1970年).

but both columns return the same (the 1970 epoch time).

我希望'now_in_mili'以毫秒为单位显示当前日期,例如 在JavaScript中是可能的:

I'm expecting 'now_in_mili' to print current date in milliseconds such as it is possible in JavaScript:

Date.parse(new Date())

推荐答案

您需要将参数传递给NOW()函数,以指定要包括的小数秒位数.它支持毫秒,但如果要毫秒,则可以使用NOW(3),然后将结果乘以1000,如下所示:

You need to pass an argument to the NOW() function to specify how many digits of fractional seconds you want it to include. It supports microseconds, but if you want milliseconds you can just use NOW(3) and then multiply the result by 1000, like this:

SELECT UNIX_TIMESTAMP(NOW(3))*1000 as now_in_mili

这篇关于MySQL UNIX_TIMESTAMP(now())-当前时间(以毫秒为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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