Suraj Gujar
Suraj Gujar

Reputation: 11

I got warning of date function as follow

Warning: date() [function.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 Asia/Calcutta for 5.5/no DST instead in E:\xampp\htdocs\suraj\central_db_system\dwnld_reg_data.php on line 8

And I resolved this warning by calling function

date_default_timezone_set('America/Los_Angeles');

But each time I have to add this function on each page.

Is there any other way to resolve this problem?

Upvotes: 0

Views: 99

Answers (5)

azzy81
azzy81

Reputation: 2289

create a php file with the following code and you should be able to see what the property is currently set to:

<?php phpinfo(); ?>

php.ini is usually a massive text file so you'd have to just open it with a simple text editor and search for the setting.

On my testing server the timezone setting looks like this:

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

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

You'd just have to change 'UTC' to whatever timezone you need. Note: if your on a shared server with a hosting company you will probably not be able to edit the PHP ini yourself and the hosting company may refuse to do this but if ifs your own server you can change what you like.

Be careful with php.ini, if you delete the wrong line it may stop php from working altogether. backup php.ini first is always wise.

Upvotes: 0

slash28cu
slash28cu

Reputation: 1634

Add date.timezone = "America/Los_Angeles" to your php.ini file.

Or:

date_default_timezone_set('America/Los_Angeles'); in a global place(bootstrap) or entry point in your app.

Or:

ini_set("date.timezone","America/Los_Angeles"); in a global place(bootstrap) or entry point in your app.

Upvotes: 1

jonas
jonas

Reputation: 126

Solutions:

  1. Create an init script and include it in every file
  2. Create a .htaccess file in your document root and write php_value date.timezone America/Los_Angeles
  3. Apply option 2 globally in your php.ini

Upvotes: 0

TerryProbert
TerryProbert

Reputation: 1134

php.ini

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = 'America/Los_Angeles'

Upvotes: 0

nickhar
nickhar

Reputation: 20883

Yes, in your php.ini file or perhaps set in a base config file using include()

Upvotes: 0

Related Questions