代码之家  ›  专栏  ›  技术社区  ›  Cody Raspien

php-mysql timezone-echo行之前添加额外的小时数

  •  0
  • Cody Raspien  · 技术社区  · 8 年前

    我有一个mysql表叫做温度

    我的一个属性叫做“现在” 它显示服务器上的时间戳。

    架构:

    now (current_time), id (auto increment), temp (varchar 50)
    

    now属性示例

    2018-06-07 11:19:46
    2018-06-08 02:06:12
    

    我无权更改服务器上的时间。

    在读取now值后,如何将5.5小时添加到now?

    我当前要读取的代码

    $sql = "SELECT id, now, temp FROM temperature";
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0) {
       while($row = $result->fetch_assoc()) {
          echo "id: " . $row["id"]. " - Time: " . $row["now"]. " . - Temperature: ". $row["temp"]. "<br>";
      }
    
     } else {
    echo "no data";
     }  
    

    这有可能吗?我能在回声前加5.5小时吗?

    3 回复  |  直到 8 年前
        1
  •  1
  •   D P    8 年前

    SELECT id, ADDTIME(now, "5:30:0") AS now_added FROM temprature;
    
        2
  •  -1
  •   O. Jones    8 年前

    Indian national time zone (+5:30) zoneinfo database Asia/Kolkata

    niversal Time Coordinated (UTC)

    now DATETIME TIMESTAMP 2018-07-08 13:31:20

    query()

    SET time_zone = 'Asia/Kolkata';
    SELECT id, now, temp FROM temperature;
    

     SELECT id, CONVERT_TZ(now,'UTC','Asia/Kolkata') AS now, temp FROM temperature
    

    https://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html

        3
  •  -3
  •   marcellio    8 年前

      $selectedTime = $row['now'];
      $endTime = date("H:i:s" ,strtotime("+5 hours 50 minutes", strtotime($selectedTime)));
      echo $endTime;