Time in PHP - MYSQL Time in ZingChart Time is 7 hours more

ZingChart:

enter image description here

MySQL table:

enter image description here

How can i fix this? The time in the graph does not correspond to the time in the database. Any help is appreciated.

Here's the script graphic:

    <script>
      <?php
        
        $query = "SELECT date,temperature from tb_temperature where date >= CAST(CURRENT_TIMESTAMP AS DATE)";

        $date = []; // Array to hold our date values
        $series = []; // Array to hold our series values

       $mysqli = new mysqli($host, $usernm, $passwd, $dbname, $port);
        if($mysqli->connect_error) {
          die('Connect Error (' . $mysqli->connect_errno . ')' . $mysqli->connect_error);
        }
        if ($result = $mysqli->query($query)) {
          while( $row = $result->fetch_array(MYSQLI_NUM)){

            array_push($date, $row[0]);
            array_push($series, $row[1]);
          }

    
          foreach ($date as &$value){
            $value = strtotime( $value ) * 1000;
          }

   
          $result->close();
        }
      ?>
   
      var dateValues = [<?php echo join($date, ',') ?>];
      var seriesValues = [<?php echo join($series, ',') ?>];
      <?php

        $mysqli->close(); 
      
      ?>
    </script>
    
Run codeHide result
+4
source share
1 answer

This is most likely an offset utc. Regardless of the time zone on the machine you are working on, this time zone is located. You can change this with the parameter utc:trueand set timezone:7to set the offset.

You can check lines 3 and 4 of the tabs JSin this demo .

+4
source

Source: https://habr.com/ru/post/1664083/


All Articles