如何在PHP中设置自己的时区


How to set my own timezone in PHP

我有一个android项目,它将新记录插入在线mySQL数据库,这是一个免费的宿主。

中的主机

我的服务器在印度(我想是的),我来自菲律宾。每次插入新数据时,它都会将DATETIME存储为服务器的时区。

我的mySQL数据是DATETIME,默认

我想插入DATETIME作为我的时区,它是亚洲/马尼拉

<?php 
    if($_SERVER['REQUEST_METHOD']=='POST'){
            date_default_timezone_set("Asia/Manila");
            $res_accession = $_POST['res_accession'];
            $res_usn = $_POST['res_usn'];
            $res_author = $_POST['res_author'];
            $res_title = $_POST['res_title'];
            $res_status = $_POST['res_status']; 
    $sql = "INSERT INTO res_library (res_accession, res_usn, res_date, res_author, res_title, res_status) 
                         VALUES ('$res_accession', '$res_usn', NOW(),'$res_author', '$res_title', '$res_status')";
    require_once('dbConnect.php');
    if(mysqli_query($con,$sql)){
        echo 'Reservation Successful';
    }else{
        echo 'Could Not Reserve';
    }
    mysqli_close($con);
}

您可以在php 中使用bool date_default_timezone_set()函数

bool date_default_timezone_set ( string $timezone_identifier )

参考

如果你想检查你的时区

<?php
    echo date_default_timezone_get();// will echo your time zone.
?>

尝试使用date()

date_default_timezone_set("Asia/Manila");
echo date("Y-m-d H:i:s");// echoes 2015-12-01 16:22:23