dougu1985 2015-12-01 08:14
浏览 35

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

i have an android project that Inserts new record to an online mySQL database, it is a free hosting.

hostinger.in

my server in located in India (i think so), and im from Philippines. every time i insert new data, it stores the DATETIME as the server's timezone.

my mySQL data is a DATETIME, default

i would like to insert the DATETIME as my timezone which is Asia/Manila

<?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);
}
  • 写回答

1条回答 默认 最新

  • doujiao9426 2015-12-01 08:16
    关注

    you can use bool date_default_timezone_set() function in php

    bool date_default_timezone_set ( string $timezone_identifier )
    

    Reference

    If you want to check your time zone

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

    Try using date()

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

报告相同问题?