PHP date showing wrong time despite the timestamp being correct

后端 未结 4 891
北荒
北荒 2021-01-04 10:41

I\'m having a problem with the PHP date function which I\'ve never had a problem with before.

The timestamp is entirely correct, however for some bizarre reason date

相关标签:
4条回答
  • 2021-01-04 10:59

    try this method will work

    for time zone http://php.net/manual/en/timezones.php

    code

    <?php
    date_default_timezone_set('Asia/Kolkata'); 
    
    $dt2=date("Y-m-d H:i:s");
    echo $dt2;
    
    ?>
    
    0 讨论(0)
  • 2021-01-04 11:02

    For time zone: https://www.php.net/manual/en/timezones.php

    date_default_timezone_set('America/Chicago');

    echo date("m/d/Y h:i:s A");

    0 讨论(0)
  • 2021-01-04 11:07

    try this

    // set default timezone
    date_default_timezone_set('UTC');
    //define unix timestamp
    $timestamp = 1456778973;
    // output
    echo date('d M Y H:i:s',$timestamp);
    

    Try this converter too http://freeonlinetools24.com/

    0 讨论(0)
  • 2021-01-04 11:14

    That time stamp is is 9am GMT timezone, if you are in another timezone then you will need to adjust it accordingly.

    http://php.net/manual/en/function.date-default-timezone-set.php

      date_default_timezone_set('Europe/London');
    

    or even better in your php.ini

    http://php.net/manual/en/datetime.configuration.php

    date.timezone="Europe/London"
    

    Or you can use more specifically GMT instead of Europe/London (which has DST)

    0 讨论(0)
提交回复
热议问题