Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Keep getting this warning message when I use PHP to display the date. How can this be fixed?
Instead of displaying the correct date, a long message comes up. the message states, "Warning: 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /Applications/MAMP/htdocs/index.php on line 87."
Any ideas on how to correct this problem?
Kevin Korte28,148 Points
According to PHP's manual here it says:
Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT or E_WARNING message if using the system settings or the TZ environment variable. See also date_default_timezone_set()
if you visit the date_default_timezone_set() you can see you can set the timezone that the
date() function will use.
Going back to the date() function it gives you this as the first example
// set the default timezone to use. Available since PHP 5.1
// Prints something like: Monday
It's not a bad idea to set the timezone, especially if you're on a smaller shared server, you likely won't have access to change it in the ini file.
Try that and see if it fixes it. Personally I've not had it happen to me, but that should take care of it. Let me know.