简体   繁体   中英

What is the rationale behind “It is not safe to rely on the system's timezone settings”?

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.

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.

After reading through this thread

http://grokbase.com/t/php/php-internals/135qbh5twa/date-timezone-e-warning-really-necessary-whats-the-rationale

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM