datetime - How can I change timezones in a php date? -
i have date stored in database in format:
2011-02-23 13:00:00
i need return in iso8601 format, needs set specific time zone (which not time zone of server.) want return this:
2011-02-23t13:00:00-0600
using code:
echo date(date_iso8601, strtotime("2011-02-23 13:00:00"));
i this:
2011-02-23t13:00:00+0000
is there way reset time zone in date or strtotime function, or need strip off 5 rightmost characters , concatenate desired timezone stamp remaining date/time?
edited add: although did accept solution below of using new datetime , setting new datetimezone, found easier way if don't need keep resetting time zone:
date_default_timezone_set('america/chicago'); $starttime = date(date_iso8601, strtotime("2011-02-23 13:00:00"));
you use datetime
class. datetime objects can initialized specific time zone, , transposed others.
modified manual:
$date = new datetime('2011-02-23 13:00:00', new datetimezone('pacific/nauru')); echo $date->format('c') . "\n"; $date->settimezone( new datetimezone('europe/berlin')); echo $date->format('c') . "\n";
Comments
Post a Comment