Reputation: 214979
In python I can do
import datetime
print datetime.datetime.now().strftime('%Y-%m-%d')
# prints `2014-06-27`.
Similarly, in node.js:
console.log(new Date().toDateString());
// Fri Jun 27 2014
When I try the same in php:
<?php
print date('Y-m-d');
?>
I'm getting this
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 ....
What is the rationale behind this message? Why don't python or node bother? What exactly is "unsafe" about using the system timezone?
Since there are many posts regarding this error, please read carefully : I'm not asking how to fix it (pretty much obviously), I'm wondering why I'm getting this message in the first place.
Upvotes: 3
Views: 161
Reputation: 214979
After reading through this thread
I understand that there are no valid technical reasons for this warning. The only reason is that someone from the php group thought it could be useful to reduce the number of bugreports on bugs.php.net. So, basically a magic_quotes
kind of stuff.
Upvotes: 0
Reputation: 75575
PHP
is traditionally used for web development, so one plausible reason would be that the consumers of a web service would not be in the same time zone as the time zone that the server is hosted in, and presumably configured for (in terms of system time).
The warning makes sense in the context of users of a system seeing the correct time on the client side.
There is some discussion of this here which mentions the justification I gave above. Another justification from the same page, from someone who is presumably a PHP language developer.
No - you, as an admin, are required to make an informed decision on what you want your timezone to be. There have been way too many bug reports where people had no clue, so now we throw a warning.
Upvotes: 3