Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix PHP errors related to timezone (function.strtotime and function.date)

Tags:

php

Upgrading to a new server, I two repeated errors:

Warning: strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EST/-5.0/no DST' instead in...

and

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EST/-5.0/no DST' instead in

How do I go about fixing these?

Code in question is this:

'date' => date("Y-M-d",strtotime($Array['_dateCreated'])),

I've tried putting this in an include at the top of all my pages:

<?php
date_default_timezone_set('America/New_York');
?>

Thanks in advance for your help.

like image 425
Keefer Avatar asked Jan 10 '12 22:01

Keefer


2 Answers

date.timezone in php.ini can fix this globally.

like image 154
Nowhy Avatar answered Oct 23 '22 11:10

Nowhy


Fixed this by putting

date_default_timezone_set('America/New_York');

In the actual file that was complaining.

like image 25
Keefer Avatar answered Oct 23 '22 13:10

Keefer