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

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

Related

Where does PHP get it's DATE information from?

I live in the UK and the current time is 02:30am on Monday 10th Feb 2014, however, my website is showing 02:30am Sunday 9th Feb 2014 - the day and date where the same before midnight so i am assuming a timezone difference. Can i set this to my own timezone ?
edit: Can i set this to the users' timezone?
That doesn't look like a timezone issue since the date if off by a full 24 hours. But just in case it is, it is set in your php.ini, and of that is not set, it defaults to the server time zone.
You can set it in your php.ini file by setting date.timezone to be the timezone of your choosing.
date.timezone = Europe/London;
If you don't have access to the php.ini you can use date_default_timezone_set to set the timezone in your scripts.
date_default_timezone_set('Europe/London');
You have two ways to define the timezone you want:
date_default_timezone_set date_default_timezone_set('Asia/Manila');
Modifying your php.ini: date.timezone = Asia/Manila
In code, you can see what the default timezone is by calling date_default_timezone_get(). You can set it programatically using date_default_timezone_set(). The preferred way to do it though is to use the php.ini settings.
I think you have to set the timezone preference in the php.ini file that initializes the PHP environment or if you don't have access to anything like that, you could look into http://www.php.net/manual/en/function.date-default-timezone-set.php

How To Change TimeZone?

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');

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

Handling timezones in PHP and MySQL?

I'm testing out making an entry system but the problem is, my host's timezone is different from where I live. It's 3am on my server while on my local computer, the time is 4pm. How do I automatically adjust code that I pull from the database to be displayed as a timezone similar to where I'm at?
You can set the default timezone using the function date_default_timezone_set(). It sets the default timezone used by all date/time functions in a script.
date_default_timezone_set('America/Los_Angeles');
Have a look at this page:
http://php.net/manual/en/function.date-default-timezone-set.php
You can find a list of timezones here
http://php.net/manual/en/timezones.php
Alternatively you could change the php.ini file if you have the permissions for it. You could change the option date.timezone to your timezone like this:
date.timezone = "US/Central"
For more information about date.timezone, go to this website:
http://kb.siteground.com/article/How_to_change_the_datetimezone_value_in_PHP.html

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