Cara menggunakan php set timezone jakarta

Bagi anda yang mempunyai masalah atau warning funtion.date, berikut cara setting Time Zone untuk PHP 5.3.0,
biasanya error yang dijumpai di website adalah seperti ini:

Table of Contents

  • Definition and Usage
  • Parameter Values
  • Technical Details
  • Change default timezone using .htaccess file
  • Change default timezone using php.ini
  • Related posts:
  • What is PHP default timezone?
  • Where is date timezone in PHP INI?
  • How do I set the timezone in Apache?
  • What is the default time zone?

Table of Contents

  • Definition and Usage
  • Parameter Values
  • Technical Details
  • Change default timezone using .htaccess file
  • Change default timezone using php.ini
  • Related posts:
  • What is PHP default timezone?
  • Where is date timezone in PHP INI?
  • How do I set the timezone in Apache?
  • What is the default time zone?

    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/Jakarta’ for ‘WIT/7.0/no DST’ instead in /home/xxxxxx/public_html/config.php on line 99

dari error diatas dapat diartikal bahwa ada kesalahan pada timezone setting jadi kita harus melakukan setting sesuai yang di infokan.

    We selected ‘Asia/Jakarta’ for ‘WIT/7.0/no DST’ instead in /home/xxxxxx/public_html/config.php on line 99

ini menandakan bahwa skrip website anda memilih setting waktu ‘Asia/Jakarta’  sehingga kita harus menyesuaikan dengan setting waktu yang ada di skrip  website kita.

Caranya adalah sebagai berikut:

Buka file php.ini, jika file blm ada anda bisa create new file php.ini

    date.timezone = {tulis timezone disini}

contohnya bila di indonesia menggunakan time zone berikut:

    date.timezone =  Asia/Jakarta

kemudian Save file php.ini dan selesai

❮ PHP Date/Time Reference

Table of Contents

  • Definition and Usage
  • Parameter Values
  • Technical Details
  • Change default timezone using .htaccess file
  • Change default timezone using php.ini
  • Related posts:
  • What is PHP default timezone?
  • Where is date timezone in PHP INI?
  • How do I set the timezone in Apache?
  • What is the default time zone?

Example

Set the default timezone:

date_default_timezone_set("Asia/Bangkok");
echo date_default_timezone_get();
?>

Try it Yourself »


Definition and Usage

The date_default_timezone_set() function sets the default timezone used by all date/time functions in the script.


Syntax

date_default_timezone_set(timezone)

Parameter Values

ParameterDescription
timezone Required. Specifies the timezone to use, like "UTC" or "Europe/Paris". List of valid timezones: http://www.php.net/manual/en/timezones.php

Technical Details

Return Value:Returns FALSE if the timezone is not valid. TRUE otherwise
PHP Version:5.1+
PHP Changelog:PHP 5.3: Throws an E_WARNING instead of E_STRICT.
PHP 5.1.2: Started to validate the timezone parameter.

❮ PHP Date/Time Reference

The default timezone for Apache/PHP is UTC (Coordinated Universal Time). Sometimes you may need to change Apache/PHP time zone to sync it with other systems or because your customers are located in a different timezone. In this article, we will look at how to change default timezone in Apache/PHP. You can use these steps to set Apache/PHP timezone as per your requirement.

Here is how to set Apache/PHP timezone. We will look at two ways to set default timezone – using .htaccess in Apache and using php.ini file in PHP.

Change default timezone using .htaccess file

In case you don’t use Apache with PHP, or you don’t have access to php.ini, you can set default time in Apache web server using .htaccess file. Before proceeding further, please make sure that you have enabled mod_rewrite (.htaccess) on your Apache web server.

Open .htaccess file, typically located at /var/www/html/.htaccess

$ sudo vi /var/www/html/.htaccess

Add the following line to set environment variable TZ (for timezone) in Apache web server to Eastern Time zone in US.

SetEnv TZ America/New_York

Save and close the file.

Also read : How to Set Up Apache Virtual Hosts in Apache

In the above line, we specify SetEnv TZ to set timezone environment variable in Apache, followed by ‘America/New York’ to specify Eastern Time. Here is a list of all available timezones in Apache/PHP.

Restart Apache Server to apply changes.

$ sudo service apache2 restart

Also read : How to Install mod_security in CentOS 7

Change default timezone using php.ini

If you don’t have access to .htaccess file or if you use PHP with Apache, then here is how to set default timezone in Apache/PHP.

Open php.ini, typically at /etc/php.ini

$ sudo vi /etc/php.ini

Uncomment/Add the following lines to set default timezone in PHP.

;[Date] 
;date.timezone = UTC

Change them to the following, to set default time to Eastern timezone.

[Date] 
date.timezone = America/New_York

Also read : How to Create Custom 404 Page in Apache

Restart Apache Server to apply changes.

$ sudo service apache2 restart

That’s it. Now your default timezone in Apache will be changed. Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!

  • About Author

This article describes how to change the time zone setting in PHP by using the date.timezone directive in a php.ini file.

The information in this article only applies to certain types of hosting accounts. To determine whether or not the information below applies to your account, please see this article.

This article assumes that you have already set up a custom php.ini file on your web site. If you have not already set up a custom php.ini file, please read this article first.

Using the date.timezone directive

By default, A2 Hosting's servers are set to use the US Eastern Standard Time zone. You can change the time zone that PHP uses for your scripts by setting the date.timezone directive in your php.ini file. For a complete list of supported time zones in PHP, please visit http://www.php.net/manual/en/timezones.php.

To change the time zone, use a text editor to modify the date.timezone directive in your php.ini file. For example, to set the time zone for Paris, France, use the following setting:

date.timezone = "Europe/Paris"

To verify the current value of the date.timezone directive and other directives, you can use the phpinfo() function. For more information, please see this article.

More Information

  • To view a complete list of php.ini directives, please visit http://www.php.net/manual/en/ini.list.php.
  • For more information about the date.timezone directive, please visit http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone.

What is PHP default timezone?

The default timezone for PHP is UTC regardless of your server's timezone. This is the timezone used by all PHP date/time functions in your scripts.

Where is date timezone in PHP INI?

ini file is located at the /etc directory. Depending on the installed version of PHP version, you will find a [Date] section like the following. If it is not there, just add a line with the "date. timezone = Your/Timezone" function.

How do I set the timezone in Apache?

Show activity on this post. You then open that file and the default is set to: date. timezone = UTC You would change this value for whatever timezone you want....

If using xampp, open xampp/php/php. ini ..

Look for the line date. timezone=Europe/Berlin and change it to your timezone. ... .

Save and restart apache..

What is the default time zone?

Unfortunately, there is no default time, so you have to change your time depending on the time zone used in the place.