简体   繁体   中英

CodeIgniter PHP Timezone and Strtotime

I'm using the following code to produce a timestamp:

date_default_timezone_set('America/Chicago');
$time = strtotime(today 08:30", $day); //$day changes 

This produces a timestamp of 1393943400 = Mar 04 2014 09:30:00

I'd ideally like to pass in a timezone, but as I'm using CodeIgniter the TimeZone definitions do not match the PHP timezones (ie UM5 for EST).

I'd welcome any thoughts!

Thanks

I use Codeigniter too and if you have PHP >= 5.2.0 you can use the DateTime object:

$system_timezone = new DateTimeZone('America/Los_Angeles'); // your timezone
$user_timezone = new DateTimeZone('America/Chicago'); // your user's timezone

$now = new DateTime(date('Y-m-d H:i:s'), $system_timezone);
$now->setTimezone($user_timezone);

echo $now->format('Y-m-d H:i:s'); // you can see the date and time of the desired timezone

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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