简体   繁体   English

Codeigniter使用时区获取当地时间

[英]Codeigniter get local time using timezone

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. 我得到的时间是提前1天,比实际当地时间晚1小时。 I'm testing the site on local server using WAMP (not sure if that's causing the issue). 我正在使用WAMP在本地服务器上测试该站点(不确定是否导致该问题)。 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. 请告知如何正确显示当地时间。

Inside your htaccess file you can insert this (right at the very top of the file) 在您的htaccess文件中,您可以插入此文件(位于文件的最顶部)

# 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. 当服务器的本地时间实际上不是“您的”本地时间时,适用于托管解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM