How To Change TimeZone? - php

i recenty try to find time zone setting in local host and work fine via edit php.ini in apache server local host.
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Karachi
and geting stuck and i try to find solution for change time zone in domain. but did not get any answer

date_default_timezone_set('Asia/Karachi');

Related

Change default timezone is not working in php

Am trying to get my current time from cpanel
am using this code
date_default_timezone_set('Asia/Kolkata');
$timestamp = date("H");
echo $timestamp;
It works fine in localhost but in cpanel it shows different time.
So I check cpanel which default time is set here
echo 'Time zone is: '.date('e');
echo 'Time zone is: '.date_default_timezone_get();
It shows the result UTC is the time zone, Now how to set my default time zone that is 'Asia/kolkata'
Anyone Please give me some idea, Thanks in Advance
My cpanel files
Try to set your timezone in php.ini and restart server.
https://www.inmotionhosting.com/support/website/php/setting-the-timezone-for-php-in-the-phpini-file
You need to set timezone for Apache(web server) or Mysql ?
do you have access to WHM?
do you have access to SSH of your server?
Which version of Apache / PHP / Mysql you are using?
if you are on shared hosting you can not do it from cPanel, thats why required above details.
Thanks

How to adjust server's time zone in Apache using wordpress?

I have developed my website in wordpress and it's error_loguses the default server time zone, but i want it to use my timezone which is Asia/Kuwait.
How to adjust/change the server to use my region's time zone.I'm using Wordpress and i have no access to the php.ini
I think you are looking for: date_default_timezone_set ( string $timezone_identifier )
You can also set this in your php.ini config.
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Europe/Berlin
You can change it in your php.ini file by changing the value of date.timezone
date.timezone = Asia/Kuwait
This link explains how to do so.
Use this reference :
http://php.net/manual/en/timezones.php
Good luck.
use below code to set your default time zone set.
paste this code in index.php file
<?php date_default_timezone_set('Asia/Kolkata'); ?>
set your timezone using wp-admin dashboard.
General Settings->Timezone

PHP: How to read the current date/time from the server, not from php.ini

Here is my problem:
echo date('Y-m-d H:i:s');
echo date('Y-m-d H:i:s', mktime());
echo exec('date');
The output is:
2012-03-21 08:45:51
2012-03-21 08:45:51
Wed Mar 21 10:45:51 EDT 2012
Server time is off 2 hours from the time returned by php date(); or any other php date/time function. It happens because server time set to EST and PHP.INI date.timezone="America/Denver"
I need to synchronize those two, by using date_default_timezone_set, but I don't know in advance what is the difference.
Is there any other way to get local server time besides calling exec?
UPD: I know that php.ini setting is wrong and that I can change it. The problem is that this script will work on nobody knows what kind of servers. I can't go to each and every one of them and correct the php.ini file. I also don't know in advance what timezone will be on those servers. I need a dynamic solution that will work everywhere.
you can change the ini date time zone and print the date
ini_set('date.timezone', 'America/Los_Angeles');
Change value of date.timezone from php.ini [Date] and restart your server.
You can get your date.timezone value form-
http://au.php.net/manual/en/timezones.php
For Bangladesh I set in my php.ini [Date]
date.timezone = Asia/Dhaka
You get your php.ini in C:\xampp\php address for XAMP server and Windows.
OR
some hosts give you possibility to edit php.ini
look for php config in cpanel
On *nix, you can use formatting parameters to date to get what you need:
date +%z — timezone (hhmm)
date +%:z — timezone (hh:mm)
date +%Z — timezone abbreviation (e.g. "EDT")
Making a system call (e.g. echo exec('date +%z');) will bypass any INI settings as per date_default_timezone_get. Note that this function issues an E_WARNING if it reads from the system time, and indeed from PHP 5.4 it doesn't even allow reading from it — specifically because it can't be relied upon.
To be consistent, regardless of the server settings you should use UTC within your application. For ease of use, GMT is close enough to UTC for most purposes, so you can use gmdate().

Wrong PHP date() output in wamp server

The problem is that date('r') returns wrong time for my timezone.
php.ini timezone setting:
date.timezone = Europe/Kiev
date_default_timezone_set('Europe/Kiev') in my script solves the problem.
So what's wrong with WAMP?
I suggest always using date_default_timezone_set() from script
e.g.
date_default_timezone_set('Europe/Kiev');
or
ini_set('date.timezone', 'Europe/Kiev');
...to avoid PHP guessing timezone.
It comes handy when you transfer code to different server(s), for example, outside of Ukraine. This line should help you to avoid unexpected (wrong) results if date.timezone is not set in php.ini or its setting is incorrect. It's also handy when you can't access and/or modify php.ini (shared hosting).
Also, be sure that you've not used ; at the and of line in php.ini.
Restart server after changing php.ini.
Edit php.ini and restart Apache:
left click to WampServer in tray icon
open php.ini (go to PHP -> php.ini)
set new date.timezone value
;date.timezone = UTC
date.timezone = Europe/Kiev
restart Apache ( go to Apache -> Service -> Restart Service )
check value of date.timezone by phpinfo();
You need to reload the configuration / restart the server after editing your php.ini file.
According to the documentation of date_default_timezone_get, the date.timezone configuration option can be overridden by setting the TZ environement variable (which, in turn, can be overridden by calling date_default_timezone_set). From your description, I suspect that the TZ environement veriable is set.
by default it shows GMT time you can change for your region with following code
date_default_timezone_set("Asia/Bangkok");//set you countary name from below timezone list
echo $date = date("Y-m-d H:i:s", time());//now it will show "Asia/Bangkok" or your date time
List of Supported Timezones
http://www.php.net/manual/en/timezones.php
I know this is an old question.
If you are using a PHP framework, you might want to check the config file of the framework. For example in Laravel, open the config/app.php and you will find timezone there. Set it to your timezone.
Open your php.ini with maybe notepad++, sublime text...
Add this line to the file: date.timezone = "X" Where X is the your time-zone of wish. Get a list of supported timezones here: http://php.net/manual/en/timezones.php
... That should do it.
3. Restart your server

PHP date() in offline WAMP differs from system time

why does the PHP date() in my offline WAMP different from my system time? how can i sync it?
You should set the default timezone. You can do this in php.ini, just add the following line:
date.timezone ="Europe/Stockholm"
You should obviously change Europe/Stockholm to your timezone. If you don't have access to php.ini, you can use date_default_timezone_set and pass your timezone as a parameter, like:
date_default_timezone_set("Europe/Stockholm");
Here is a list of supported timezones.

Categories