Home > Backend Development > PHP Tutorial > unix-时间戳 - php生成javascript风格时间戳

unix-时间戳 - php生成javascript风格时间戳

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:47:00
Original
1169 people have browsed it

众所周知,php的

<code class="lang-php">time();
mktime();
</code>
Copy after login
Copy after login

函数可以生成10位的Unix时间戳,但是在javascript中,使用

<code class="lang-javascript">new Date().getTime()
</code>
Copy after login
Copy after login

函数得到的时间戳是13位精确到毫秒的。
所以请问能否实现使用php生成一个javascript风格的Unix时间戳呢?


PS:要求php代码运行后没有任何多余的输出,只是单纯的输出一个13位的Unix时间戳。
PPS:time()*1000不算。time()+随机数同样不算。。。

回复内容:

众所周知,php的

<code class="lang-php">time();
mktime();
</code>
Copy after login
Copy after login

函数可以生成10位的Unix时间戳,但是在javascript中,使用

<code class="lang-javascript">new Date().getTime()
</code>
Copy after login
Copy after login

函数得到的时间戳是13位精确到毫秒的。
所以请问能否实现使用php生成一个javascript风格的Unix时间戳呢?


PS:要求php代码运行后没有任何多余的输出,只是单纯的输出一个13位的Unix时间戳。
PPS:time()*1000不算。time()+随机数同样不算。。。

我错了。发完问题就找到了答案。原来php提供了另一个函数来完成这个任务。

<code class="lang-php">round(microtime(true) * 1000)
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template