Follow Me
Subscribes Hell Buddy Solution.

Back To Top

Feel Glad finally done the Meta Tags generator and video :) project
- type: seo html - 30 September 2014 Tue @Hell Buddy

Home Message Share Translate

PHP date_default_timezone_set()

31October 2014

timezone set E_WARNING

Warning: strtotime()[function.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...on line 3".

Read the content or code / instruction -

What's this E_WARNING?

If you used PHP version is 5 or greater than 5, you'b better to check on, the note told us

"Since PHP 5.1.0(when the date/time functions were rewritten), every call for this date time functions will generate a E_NOTICE or E_WARNING message if the timezone isn't setting."

We have 2 solutions to solve this problem...

  1. You can change the default date timezone set in your ini. File.

    ; date.timezone = // take out semi-colon ; in the front

    date.timezone = "America/New_York" // add the timezone identifier

    sudo apachectl restart // after save the ini file, restart your apache server at Terminal.

    However, it's little bit complicated sometimes for it if you didn't really handle it well. If you can't change default timezone on your ini file for some reasons; or maybe, you need create a new website and want to show different date time, to target different timezone people. So, the next solution is the right way and will get more easier.

  2. date_default_timezone_set();

    date_default_timezone_set(); // set default timezone to close out the warning message

    date_default_timezone_set( ' timezone identifier ' ); // put timezone identifier into parameter


    echo date(); // use date() function echo default current date time

date format parameter string

The characters to format the date string -

echo date('dS F Y - g : i : s A l T'); // example output: 23rd October 2014-10:02:40 PM Thursday MST

For example;

d=2 digits day of month
S=English ordinal suffix for day of month(You can also use "jS")
F=full textual of month
Y=4 digits of year
g=12 hours format of hour
A=uppercase of AM / PM
l=full textual representation of day of week
T=Timezone abbreviation

The great thing when using timezone set function, put the uppercase T into date string format parameter. It will easily to echo out abbreviation of the specific timezone identifier.

How to make your own datetime post stamp or current date timestamp?
Break down the variables and echo individually upon each variable, put those into HTML table whatever presentation you like. Try the timezone demo at code instruction as below;

open the content >>

tag PHP - html
Programming Web Development Networking FunG project

Topic Discussion:

No Topic Discuss Now...