How to express date and time in "Y-m-d TH:i:sp" format, with UTC zone 03:00

Asked

Viewed 620 times

1

Following the documentation, I am trying to represent the date in the following format:

2017-01-07T11:20:00-03:00

Code:

$dt = $_POST['data-emissao'];
$date = new DateTime($dt, new DateTimeZone('America/Sao_Paulo'));
$data= $date->format("Y-m-d\TH:i:sP");
echo $data;

and I’m getting:

2017-01-07T13:32:00-02:00

Reference: http://php.net/manual/en/datetime.settimezone.php

1 answer

2


Hello, you are correct to return, we are in Daylight Saving Time. You have set the Time Zone "America/Sao_paulo" which at the moment is -02:00 instead of -03:00.

If you want to get at all times -03:00 independent of daylight saving time so the simplest is to use a literal string -03:00, as it makes no difference what Daylight Saving Time.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.