Search code examples
phpmysqlchartscanvasjs

How to display formatted datetime in CanvasJS chart?


how can I display the formatted datetime in canvas js chart?

 <?php $dateTime = new DateTime($row['Time']);
$formatted = $dateTime->format("g:i:s:v a F j, Y");?>          

that is how I show my date on another page, the problem is this one

$a = array("y" => $row['setPercent'], 'label' => date("g:i:s:v a F j, Y ", strtotime($row['setTime'])));
        array_push($dataPoints, $a);

how do I use the top code in order to show the milliseconds in the chart, this

 date("g:i:s:v a F j, Y ", strtotime($row['setTime'])) 

shows 12:05:10:000 pm April 25,2018 doesn't show the milliseconds.


Solution

  • Just use the code from the top with the $row['setTime'] value and insert it into the array.

    $dateTime = new DateTime($row['setTime']);
    $setTime = $dateTime->format("g:i:s:v a F j, Y");
    
    $a = array("y" => $row['setPercent'], 'label' => $setTime);
    array_push($dataPoints, $a);