PHP generating 13-digit timestamp like mktime
16,791
Solution 1
You are looking for microtime()
If you want to create microtime from a specific date, just add 000
. Because in the end, the microtime is only 1 second.
Solution 2
Make milliseconds:
$milliseconds = round(microtime(true) * 1000);
echo date("Y-m-d",($milliseconds/1000));
Author by
user1643156
Updated on June 19, 2022Comments
-
user1643156 almost 2 years
Possible Duplicate:
php get microtime from date stringFor a specific purpose, I need to get the 13-digit timestamp for a date/time, but I couldn't find a solution for this.
Like mktime in PHP, we can get a 10-digit timestamp
echo mktime($hour, $minute, $second, $month, $day, $year);
This outputs something like 1346689283.
So what about the 13-digit timestamp? Is PHP itself capable of generating such timestamps?
-
Gordon over 11 yearsyes, but I think he wants something that can create microtime from arbitrary dates, like mktime or strtotime would allow for unix timestamps
-
Rene Pot over 11 years@gordon well added that to the answer
-
user1643156 over 11 yearsyep, Gordon's right, microtime() generates CURRENT timestamp with microseconds, and it will not allow me to specify year/month/day/hour/... Example: I need to get the 13-digit timestamp for 1998-02-13 17:44
-
Terry Seidler over 11 yearsBut there are no microseconds in "1998-02-13 17:44"? You might as well add '000' like Rene Pot said.
-
Rene Pot over 11 years@user1643156 the microseconds are 1 second. Do you need it so specific? You can add any 3 random numbers like you want. It is not gonna make a big difference anyways.
-
user1643156 over 11 years@Rene Pot, by adding 000 seems not working (maybe just in the program I'm using), it results a 1970 error. but 001 - 999 they all work. Anyway, why didn't I just try adding 3 numbers before posting... :) thanks!