- Настройка Timezone в php.ini
- Настройка Timezone в php.ini
- Добавить комментарий Отменить ответ
- Рубрики
- соц сети
- Архив новостей
- Свежие записи
- Свежие комментарии
- Php ini change time
- How to set PHP timezone in php.ini
- Change Timezone In PHP
- date () and time () function
- Set Timezone In PHP.ini
- Longitudes and latitudes of a number of major cities
- Change Timezone date_default_timezone_set( )
- Convert Time in One Zone to Another Zone
Настройка Timezone в php.ini
Настройка часового пояса (по умолчанию) очень необходим для правильной обработки данных. Эта статья «Настройка Timezone в php.ini» поможет вам узнать, как можно настроить часовой пояс в файле конфигурации PHP (php.ini) или внутри любого PHP-скрипта для временного использования.
Настройка Timezone в php.ini
Для установки часового пояса по умолчанию для вашей PHP среды, выполните следующие 4 простых шага.
1. Необходимо найти конфигурационный файл php.ini и это можно сделать:
По умолчанию php.ini лежит в:
Для CentOS,RedHat или Fedora будет лежать:
Для Ubuntu, Debian или LinuxMint будет лежать:
2. Следующим действием будет поиск временных зон ( для вашей локации), для этого, стоит посетить сайт и найти свою зону для php:
3. Прописываем найденную зону в файл php.ini. Для примера, я возьму свою зону — ‘Europe/Kiev’. Открываем конфигурационный файл и делаем изменения:
ВНИМАНИЕ! Поищите опцию «date.timezone» в данном файле, возможно данный параметр уже прописан.
4. Перезапускаем веб-сервер:
Если другой сервер (nginx, tomcat, lighttpd), то перезапустите его.
Так же, можно прописать данный параметр в самом php файле следующим образом:
Настройка Timezone в php.ini завершена.
Добавить комментарий Отменить ответ
Этот сайт использует Akismet для борьбы со спамом. Узнайте, как обрабатываются ваши данные комментариев.
Рубрики
- Arch Linux (167)
- Commands (36)
- Debian’s (635)
- Administration tools Ubuntu (37)
- Backups Debian’s (7)
- Database в Ubuntu (58)
- Games (игры) (1)
- Monitoring в Debian и Ubuntu (49)
- Virtualization в Ubuntu / Debian/ Linux Mint (41)
- Docker (22)
- Kubernetes (6)
- KVM (4)
- OpenVZ (3)
- Vagrant (5)
- VirtualBox (6)
- ArgoCD (1)
- Concourse (1)
- Gitlab (1)
- Jenkinks (4)
- Spinnaker (1)
- Apache (32)
- Cherokee (1)
- FTP-services (5)
- Lighttpd (1)
- Nginx (26)
- PHP (27)
- Proxy для Debian’s (2)
- Tomcat (4)
- Панели управления в Ubuntu/Debian/Mint (24)
- Установка и настройка почты на Ubuntu/Debian (12)
- Хранилища (clouds) (2)
- Administration tools freeBSD (19)
- Database во FreeBSD (52)
- Monitoring во freeBSD (37)
- Virtualization во FreeBSD (22)
- VoIP (1)
- Установка Web сервисов (91)
- Установка и настройка почты (6)
- Установка из ports (пакетов) (19)
- Установка из sorce code (исходников) (23)
- Непрерывная интеграция (CI) (27)
- Database в MacOS (36)
- Monitoring в Mac OS (31)
- Security (безопасность) (12)
- Virtualization в Mac OS (30)
- Docker (19)
- Kubernetes (6)
- Vagrant (5)
- VirtualBox (5)
- ArgoCD (1)
- CircleCI (1)
- Concourse (1)
- Gitlab (1)
- Jenkinks (4)
- Spinnaker (1)
- Administration tools CentOS (49)
- Backups RPM’s (4)
- Database в CentOS (68)
- Monitoring в CentOS (67)
- Virtualization в CentOS/ Red Hat/ Fedora (42)
- Docker (23)
- Kubernetes (6)
- KVM (5)
- OpenVZ (2)
- Vagrant (5)
- VirtualBox (6)
- VMWare (3)
- ArgoCD (1)
- Concourse (1)
- Gitlab (1)
- Jenkinks (4)
- Spinnaker (1)
- Apache (35)
- Cherokee (1)
- DNS (3)
- FTP (10)
- Nginx (33)
- PHP (34)
- Proxy для RedHat’s (2)
- Tomcat (2)
- Voice (2)
- Панели управления в CentOS/Red Hat/Fedora (27)
- Прокси сервер на CentOS/RHEL/Fedora (4)
- Установка и настройка почты на CentOS/RHEL/Fedora (14)
- Хранилища (clouds) (1)
соц сети
Архив новостей
Свежие записи
Свежие комментарии
- Глеб к записи Установка Adobe Flash Player в Debian/Ubuntu/Mint
- Максим к записи Заблокировать User Agents используя Nginx
- Денис к записи Как включить EPEL репозиторий на CentOS
- Гость к записи Закомментировать/Раскомментировать строки vi/vim в Unix/Linux
- Sergey к записи Установка и настройка OpenVPN сервера на Debian/Ubuntu/Linux Mint
Php ini change time
U.S. Dollar Euro British Pound Canadian Dollars Australian Dollars Indian Rupees China Yuan RMB More Info →
We stand with our friends and colleagues in Ukraine. To support Ukraine in their time of need visit this page.
How to set PHP timezone in php.ini
You can configure PHP setting to use your local time zone by setting the date.timezone directive in php.ini.
List of available time zones can be found here.Follow these instructions depending on the shared hosting plan you are using:
How to change ‘date.timezone’ on shared servers
1. Go to your cPanel account >> the Files section >> the File Manager menu:
2. Navigate to the root folder of your website (by default, it is public_html for the main domain and yourdomain.com for addon domains). If you don’t have the php.ini file yet, feel free to create it using the «+ File» button:
Right-click the file and select Code Edit:
date.timezone = «Place/Your_town»
change Place/Your_town to the preferred time zone:
4. Click Save Changes.
5. Next, add an LSPHP directive rule to your .htaccess file. You can learn more about the LSPHP handler here.
Add the following lines to the .htaccess file (.htaccess is a hidden file. To see such files, click Settings in the upper right corner of the File Manager, check Show hidden files (dotfiles), then Save):lsapi_phpini /home/cPanel_user/public_html/php.ini
Replace the cPanel_username with your actual cPanel username. If your php.ini file is located in a different directory, change the path accordingly:
6. Click Save Changes.
Before editing/creating the php.ini file on a business server, you will need to check the PHP version that is set for the domain.
1. Go to cPanel account >> the PHP Tweaks menu and select the domain from the drop-down menu. Check the PHP version used for this domain:
2. Next, go to the Files section >> the File Manager menu:
3. Enable Show hidden files (dotfiles) in the Settings menu:
4. Navigate to /home/cPanel_user/.system-php/ini/PHP_ver/yourdomain.com (where PHP_ver is the PHP version used for the domain):
5. If the php.ini file is not present in this folder, create it by using the «+ File» button:
6. Right-click php.ini >> select Code Edit:
date.timezone = «Place/Your_town»
change Place/Your_town to the preferred time zone:
Change Timezone In PHP
In this tutorial we will let you know about different time zones and how to set them as default zone in PHP.
A time zone is a region on Earth that has a uniform standard time for legal, commercial, and social purposes. It is convenient for areas in close commercial or other communication to keep the same time, so time zones tend to follow the boundaries of countries and their subdivisions.
This is the Description for time zone in Wikipedia
When ever it comes to time its important to make sure that the users get the time displayed in their local time to avoid errors, especially when you have offices or users in different parts of the world.
To make sure that all the user gets all the time displayed in confortable format.
To make that happen you can save the times in default UTC format in database and convert them and display it to the users according to their desired time zone, or if you have all the users from same time Zone, and the time zone is not UTC then you can still follow the same method, you can also red ice the unnecessary server load by setting the default time zone to the desired time in PHP.INI file or to with set default time zone function.
Both the methods are explained here.
date () and time () function
Before we get started with changint time zones , lets take a look at the time() and date() functions.
time() function returns a string formatted according to the given format string using the given integer timestamp, if no format is mentioned it take the current time.
The following code time(‘d-M-Y’,$time) gives an out put in the form DD-MMM-YYY depending on the value of $time .
The following characters can be used in the format parameter string
d - Day of the month, 2 digits with leading zeros D - A textual representation of a day, three letters m - Numeric representation of a month with leading zeros M - short textual representation of a month g - 12-hour format without leading zeros 1 through 12 G - 24-hour format without leading zeros 0 through 23 h - 12-hour format with leading zeros 01 through 12 H - 24-hour format with leading zeros 00 through 23 a - Ante meridiem and Post meridiem am or pm A - Ante meridiem and Post meridiem AM or PM i - Minutes with leading zeros s - Seconds, with leading zeros
Complte characters that can be used in time from PHP.net
Set Timezone In PHP.ini
This method can only be used on your local server or if you have the permission to edit the PHP.INI file of the server.
You need permission to edit PHP.ini file to do this, which none of the web hosts give you permission.You can use this in your local server or if you have your own Server
To change the default time zone , open the PHP.ini file in any text editor then search for date.timezone , by default it will be set to UTC ,the Latitude’s and longitudes will be commented , so delete the Semicolon and Change that to your desired location
date.timezone = "Asia/Delhi" date.default_latitude = 28.40 date.default_longitude = 77.13
When we tested this method on WAMP server, the PHP gave the following error. Any way it’s not recommended to rely on system time.
Requires:PHP 5.0.0.So this method is not recommended unless you are confident with your self
Longitudes and latitudes of a number of major cities
// --- Asia --- // // Baku, Azerbaijan, Asia date.timezone = "Asia/Baku" date.default_latitude = 40,2343 date.default_longitude = 49,5256 // Shanghai, China, Asia date.timezone = "Asia/Shanghai" date.default_latitude = 31.5167 date.default_longitude = 121.4500 // Delhi, India, Asia date.timezone = "Asia/Delhi" date.default_latitude = 28.40 date.default_longitude = 77.13 // Colombo, Sri Lanka, Asia date.timezone = "Asia/Colombo" date.default_latitude = 6.9319444 date.default_longitude = 79.8477778 // --- Australia --- // // Canberra, Australia date.timezone = "Australia/Canberra" date.default_latitude = -35.308142 date.default_longitude = 149.124518 // --- Europe --- // // London, England, Europe date.timezone = "Europe/London" date.default_latitude = 51.500181 date.default_longitude = -0.12619 // Berlin, Germany, Europe date.timezone = "Europe/Berlin" date.default_latitude = 52.5194 date.default_longitude = 13.4067 // Madrid, Spain, Europe date.timezone = "Europe/Madrid" date.default_latitude = 40.416126 date.default_longitude = -3.696706
Change Timezone date_default_timezone_set( )
This method is pretty straight forward as there is no much configuration needed. Just make a call to date_default_timezone_set( ) function with the requires time zone as argument in single quotes, all the date() following below will display the time in the requested time zone. The date() or time() mentioned above the function call will display the UTC time or as configured in PHP.ini file.
echo "Original Time: ". date("h:i:s")."\n" date_default_timezone_set('Asia/Kolkata'); echo "Indian Standart time Time: ". date("h:i:s")."\n";
The Output for above code is given below. it displays the time in Indian Standard time(IST)
Original Time: 10:45:23 Indian Standart time Time: 04:15:23
Using the above two functions You cannot change the time stored in database to your desired one.
Convert Time in One Zone to Another Zone
If you have time stored in your data base in some other zone and you need that in another, you cannot achieve that with the above things, even if you have users using different Time zones, you can do that with this as the user can set the desired time as he needs it.
To get that done you need to make a standard in storing the time in the database. We recommend to use UTC as its will be easier for conversion. Any format will do fine but you may need to do some more works to get the conversion done.
Given below is a sample code on how to change the time from one zone to another, you can change the zone to desired one to use it.
$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru')); echo $date->format('Y-m-d H:i:sP') . "\n"; $date->setTimezone(new DateTimeZone('Asia/Kolkata')); echo $date->format('Y-m-d H:i:sP') . "\n";
All Time zones supported in PHP from PHP.net