php - Convert microtime(true) to javascript date object
Get the solution ↓↓↓Solution:
You can easily use the output ofmicrotime
to create a JavaScript Date object, like this:
new Date(<?php echo microtime(true) * 1000 ?>)
Couple things to note here though.
microtime(true)
returns time in seconds, accurate to microseconds. You have to multiple this by 1000 to have a millisecond value for yourDate
object.- You are only then preserving millisecond precision, not the entire microsecond precision. JavaScript's
Date
does not support sub-millisecond precision.
(Also, I assume you'll pass the microtime value from the server some other way, hopefully you're not actually spitting out PHP in the middle of your JavaScript code.)
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the requested url was not found on this server. xampp
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.