Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
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,135 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
<?php // set the default timezone to use. Available since PHP 5.1 date_default_timezone_set('UTC'); // Prints something like: Monday echo date("l");
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.