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

How to get the current timestamp in php

angryTom
angryTomOriginal
2019-10-30 09:41:197859browse

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;
?>

Effect:

1572399129
2019-10-30 01:32:09

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();

Effect:

1572399322
1572399322925

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!

Statement:
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

Related articles

See more