简体   繁体   中英

PHP strtotime function - not safe to rely on system's timezone?

I want to convert a date - 2012-05-25 to the unix timestamp. When i'm using the strtotime() function, it says

PHP Warning: 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 'Asia/Calcutta' for 'IST/5.0/no DST' instead in /var/www/html/__modules/tickets/library/Notification/RD_time.php on line 323.

Please help me out. I need to flush these reports by tonight.

Just do what it says in the warning and use date_default_timezone_set

For example:

date_default_timezone_set('America/New_York');

You can add the following at the beginning of your code:

date_default_timezone_set('Africa/Lagos');//or change to whatever timezone you want

If you want to make this one time, you can put the timezone in your php.ini file. You can search for date.timezone , You should have a block like this in your php.ini file:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Africa/Lagos

Be sure to restart the server ( service httpd restart on linux).

The list of timezones can be found here http://www.php.net/manual/en/timezones.php .

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