简体   繁体   中英

get actual date in unix timestamp and the convert it to gmt-3 in php

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

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

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