Convert PHP time to Javascript time in PHP
Get the solution ↓↓↓How to convert PHP time to Javascript time in PHP? My PHP code:
<?php
$times = array(/* A list of time with "Y-m-d h:i:s" format goes here */);
$return = '[';
$i = 1;
foreach($times as $time) {
$return .= '['.strtotime($time).','.$i.'],';
//In my opinion, converting time to
//js time at here is good choice
if($i==100) {
break;
}
$i++;
}
$return = substr($return, 0, -1).']';
?>
My script:
<script>
var results = [{
label: "Buy in",
data: <?=$return?>
}];
</script>
Answer
Solution:
use the output of PHP'sdate()
and Javascript time is in the same format, but multiplied by 1000 because it has millisecond resolution.
Answer
Solution:
Final code:
<?php
$times = array(/* A list of time with "Y-m-d h:i:s" format goes here */);
$return = '[';
$i = 1;
foreach($times as $time)
{
$return .= ('['.strtotime($time)*1000).','.$i.'],';
if($i==100)
{
break;
}
$i++;
}
$return = substr($return, 0, -1).']';
?>
Thank you very much:D! Some time I have stupid thinking like :"How to call js function from php code" for this case. I have to learn more and more...
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: to enable extensions, verify that they are enabled in your .ini files
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.