Reputation: 1793
I need to get current unix timestamp and then convert it to my local time which is GMT-3, Buenos Aires.
I've done some research but I just can't find a post that fits my problem.
To ask for actual date I do:
$date = new \DateTime();
which returns this date object:
object(DateTime)[28]
public 'date' => string '2015-06-03 11:06:18.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'America/Buenos_Aires' (length=20)
HOw can I access to timezone_type? it gives me error if I do $date->timezone_type
and how can I convert unix timestamp to gmt-3?
Dates are driving me crazy, please help
Upvotes: 1
Views: 1025
Reputation: 922
I hope below example will help you.
$day = date('Y-m-d', time());
$date = new DateTime($day, new DateTimeZone('Pacific/Nauru'));
echo $date->format('Y-m-d H:i:sP') . "\n";
$date->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo $date->format('Y-m-d H:i:sP') . "\n";
example output is
2015-06-03 00:00:00+12:00
2015-06-03 01:45:00+13:45
Upvotes: 3