Asked  7 Months ago    Answers:  5   Viewed   29 times

I'm using php5.5 and getting this error whenever I used the date function in PHP:

 Warning: phpinfo(): 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 /var/www/info.php on line 1

the loaded configuration file is here:


so I changed the date.timezone setting into this:

; Defines the default timezone used by the date functions
date.timezone = Asia/Jakarta

;date.default_latitude = 31.7667

;date.default_longitude = 35.2333

;date.sunrise_zenith = 90.583333

;date.sunset_zenith = 90.583333

Then I restart the server:

sudo /etc/init.d/apache2 restart

but still getting this error, I tried to check the .ini file in the Additional ini file location but none of it is overriding the date.timezone setting

I've checked the php.ini file permission, but still not working please guide me to solve this problem, thanks..



finally solved my problem, this is my Loaded Configuration File:


modified the date.timezone here but it's not working.

So, I check the "Scan this dir for additional .ini files " values in phpinfo() which point to:


then I search date.timezone from all files in that folder but found none.

this is my Additional .ini file parsed value in phpinfo():

/etc/php5/apache2/conf.d/05-opcache.ini, /etc/php5/apache2/conf.d/10-pdo.ini, /etc/php5/apache2/conf.d/20-json.ini, /etc/php5/apache2/conf.d/20-mysql.ini, /etc/php5/apache2/conf.d/20-mysqli.ini, /etc/php5/apache2/conf.d/20-pdo_mysql.ini, /etc/php5/apache2/conf.d/20-xdebug.ini, /etc/php5/apache2/conf.d/30-mcrypt.ini 

I modified /etc/php5/apache2/conf.d/20-xdebug.ini, and appended this line:

date.timezone = Asia/Jakarta

very weird but this solved my problem !!!

Wednesday, March 31, 2021
answered 7 Months ago

You can use the datetime object or their function aliases for this:

Example (abridged from PHP Manual)


$datetime = new DateTime('2008-08-03 12:35:23');
echo $datetime->format('Y-m-d H:i:s') . "n";
$la_time = new DateTimeZone('America/Los_Angeles');
echo $datetime->format('Y-m-d H:i:s');

Edit regarding comments

but i cannt use this method because i need to show date in different time zones as the user login from different locations

That's not a problem. When a user logs in, you determine his timezone and set it to your DateTime object just like shown. I'm using a similar approach in one of my projects and it works like a charm.

in the database i need to get the dates in any single timezone, then only it can be processed properly

You store the time either as a timestamp or a datetime in one timezone. When you query a DateTime field, you either convert the time in a DateTime object to this timezone or - if your db supports it - query with the selected timezone.

Tuesday, June 1, 2021
answered 5 Months ago

Yes, you can specify the filename just like you'd do for content-disposition: attachment, i.e. like this:

Content-disposition: inline; filename=""

See this post for some useful information about this header: How to encode the filename parameter of Content-Disposition header in HTTP?

Friday, August 6, 2021
answered 3 Months ago

I got the solution, so i would like to share

Actually I have set default timezone in file as below


then I check the current time and timezone of MySQL server from phpmyadmin with below query

SELECT NOW(), SYSDATE(), @@global.time_zone , @@session.time_zone , 
      TIMEDIFF( NOW( ) , CONVERT_TZ( NOW( ) , @@session.time_zone ,  '+00:00' )) 

This return the OFFSET value +05:30

solution steps:

  • First I changed the timezone of mySQL Server to GMT/UTC +00:00 ( I have super privilage on mySQL server)

    SET GLOBAL time_zone = '+00:00';  
  • We save the date and time using start_date = NOW() ( column datatype: DATETIME )

Now there is 2 way to get date and time as per user's timezone (America/Denver)

first method ( using PHP DateTime)

   * first set timezone as GMT.
   * This is MUST because default timezone is differ from user timezone  
    $gmt = new DateTimeZone('GMT');
    $user_tz = 'America/Denver';
    $st = new DateTime($row[`start_date`], $gmt);
    // now set user timezone
    $st->setTimezone($user_tz );
    $stime = $qt->format('r');
    echo $stime;

second method (using MySQL UNIX_TIMESTAMP)

#$retrieve data from server in timestamp
$qry = "SELECT `start_date`,UNIX_TIMESTAMP(`start_date`) AS sTimestamp FROM..."  
$st = new DateTime('@'.$row['sTimestamp ']);                     
$stime = $st->format('r');
echo $stime;

Note : dont change start_date to timestamp with strtotime(). It will return different value from the UNIX_TIMESTAMP() i.e.

 strtotime($row['start_date']) !== $row['sTimestamp']
Saturday, August 7, 2021
answered 3 Months ago

These are html entities, works in android studio as well:

> can be replaced with >
< can be replaced with &lt;
" can be replaced with &quot;, &ldquo; or &rdquo;
' can be replaced with &apos;, &lsquo; or &rsquo;
} can be replaced with &#125;
& can be replaced with &amp;
space can be replaced with &#160;
Tuesday, August 24, 2021
Tommy Andersen
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :