double0201 2012-06-03 21:32
浏览 60
已采纳

Codeigniter使用时区获取当地时间

I’m simply trying to display my local time in Miami using the following code:

date_default_timezone_set('America/New_York'); //is added in library 
$timestamp = time();
$timezone = 'UM5'; //(UTC - 5:00) Eastern Time, Bogota, Lima, Quito
$daylight_saving = TRUE;
$miamitime = gmt_to_local($timestamp, $timezone, $daylight_saving);

echo unix_to_human($miamitime); // U.S. time, no seconds 

The time I’m getting is 1 day ahead and 1 hour behind the actual local time. I’m testing the site on local server using WAMP (not sure if that's causing the issue). It looks to me like I’m setting everything right.. I’m not sure what is causing this. Please advise how to correctly display my local time.

  • 写回答

1条回答 默认 最新

  • du1913 2012-06-04 07:32
    关注

    Inside your htaccess file you can insert this (right at the very top of the file)

    # Set PHP Time Zone:
    SetEnv TZ America/New_York
    

    It will force your server to be set to whatever timezone you want. Good for hosted solutions when the local time of the server is not actually "your" local time.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序