Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP date() shows tomorrow's date

Tags:

php

I have an odd error. If I call:

 date("js M")

it shows tomorrow's date, I don't know what changed because yesterday that function was working just fine. I haven't tested anything in production, as far as I can see, it only happens in localhost.

I already checked my clock and it is right, is there any other place where PHP fetches the date? What could have changed? Thank you!

like image 443
ILikeTacos Avatar asked Dec 27 '22 19:12

ILikeTacos


1 Answers

By Default the date() function uses a unix timestamp, which is always set to +0:00.

date_default_timezone_set('America/New_York');

If you set the default timezone, the unix timestamp used will apply the correct offset to your location and you should be getting the correct day for you no matter where you are.

like image 122
Jonah Katz Avatar answered Jan 11 '23 03:01

Jonah Katz