Home > Backend Development > PHP Problem > How to get the current timestamp in php

How to get the current timestamp in php

angryTom
Release: 2023-02-28 06:32:02
Original
7920 people have browsed it

How to get the current timestamp in php

php gets the number of digits of the current timestamp

php gets the 10 digits of the current timestamp.

Example:

<?php
//unix时间戳
$time = time();
//转成时间格式
$dadte = date(&#39;Y-m-d H:i:s&#39;,$time);
echo $time;
echo "<br>";
echo $dadte;
?>
Copy after login

Effect:

1572399129
2019-10-30 01:32:09
Copy after login

java, the timestamp of javascript is 13 digits, how to implement php to obtain the 13-digit timestampHere, let’s look at the code

<?php
function getUnixTimestamp ()
{
    list($s1, $s2) = explode(&#39; &#39;, microtime());
    return (float)sprintf(&#39;%.0f&#39;,(floatval($s1) + floatval($s2)) * 1000);
}
echo time();
echo "<br>";
echo getUnixTimestamp();
Copy after login

Effect:

1572399322
1572399322925
Copy after login

For more PHP-related knowledge, please visit PHP Chinese website!

The above is the detailed content of How to get the current timestamp in php. For more information, please follow other related articles on the PHP Chinese website!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template