douding7189 2013-10-27 10:02
浏览 37
已采纳

在php中设置时区

I'm using the following code to get server time. But I'm in Bangladesh and I don't get Bangladeshi time by this. Please tell me where I have to change for the exact Bangladeshi time.

$Vdate=date("F j, Y, g:i a");
  • 写回答

6条回答 默认 最新

  • douzhi3779 2013-10-27 11:29
    关注

    Function date_default_timezone_set()>= 5.1.0 set timezone globally.

    If you need to set timezone locally, for specific variable, you can use DateTime>= 5.2.0 and DateTimezone>= 5.2.0 classes, like:

    $dt = new DateTime('now', new DateTimezone('Asia/Dhaka'));
    echo $dt->format('F j, Y, g:i a');
    

    Here is the list of all available timezones in PHP.


    Since non of the above functions will work on PHP version 4.x, you have no other way to set timezone, rather that setting your server time to your timezone, or add offset to time() functions, like:

    echo date('F j, Y, g:i a', time() - 6*3600); # Bangladesh is in UTC+6
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?