2
votes

I'm using Carbon in Laravel to do some work on dates. I quickly realized that my local copy of PHP was set for UTC, so in my code I'm setting the timezone in Carbon:

$dt = Carbon::now('America/New_York');

Strangely, it's still spitting out a date that is one hour behind New York time:

echo $dt;

Yields:

2017-07-25 16:29:37

But it is currently 5:29pm

It seems as though it's an hour off because it's not factoring in daylight savings time. I can't find anything on StackOverflow or Google related to daylight savings time in Carbon, everything I read just says if you set the timezone correctly, it will account for DST on its own.

1
have you checked the datetime in your php.ini file and check this answerAmr Aly
I checked my php.ini, it's set to the same thing: date.timezone = "America/New_York" Unfortunately I didn't find anything else in the answer you linked to that would explain this either.carbide20
try to echo time using native php function like echo date("Y-m-d h:i:sa"); and see if you get the correct time according to your timezoneAmr Aly
Confirmed, this does output the right time. I also echoed my phpinfo() just to ensure that the PHP being executed is the same PHP as the php.ini I checked the timezone setting on. Timezone matched what I set in php.inicarbide20
Check the settings in laravel/config/app.php line ~ 67 -> 'timezone' => __Antonios Tsimourtos

1 Answers

2
votes

Remove where you are setting the timezone with Carbon.

Inside config/app.php there is a line:

'timezone' => ''

set it to:

'timezone' => 'America/New_York'

It will set the default timezone for your app. After setting that you will get the DST adjusted New York time.