Change default timezone is not working in php - 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

Related

MySql: unchangeable timezone

my hosting provider is Godaddy My server location is in Europe and It is in the Amsterdam time zone. support team says :
"As this is a s\hared hosting platform you would be able to get the
time zone which is installed in parent server.you cannot change it" .
i want to show Australian timezone. php.ini is not provided. both mysql Timestamp and PHP function date() showing wrong time.
PHP:
http://php.net/manual/en/function.date-default-timezone-set.php
ini_set('date.timezone', 'Australia/Australian');
I'm not sure about: Australia/Australian
You can update it :)
MySQL:
https://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html

Why date ("c") produce this strange result?

$now= date ("c");
I used a local Apache server and the result:
2015-01-12T23:12:00+08:00
Now here is a problem
Now, at my computer the hour is 22:12 not 23:12
Also my time zone is Jakarta which is +7 not +8
So why does the code produce 2015-01-12T23:12:00+08:00
My apache installation got the timezone somewhere. Somewhere wrong. Where?
Try adding date_default_timezone_set("Asia/Jakarta") at the very top of your PHP file. If that works, change your php.ini to always use the correct timezone (date.timezone="Asia/Jakarta"). That way, you'll reflect the correct timezone of the server (in this case your computer).
To see what the time is in another timezone, you could do what N.B. suggested in the comments to this answer:
$dt = new DateTime("now", new DateTimeZone('Europe/Paris')); //If that's the timezone.
echo $dt->format('c');
I think it's server related stuff and you have to reconfigure the timezone of the server. In php.ini check out the value of date.timezone.

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 current time - php time function

I have a problem with the time function in PHP.
It provides a different time.
For example, the current time in my PC is 10:00AM, it appears 5 hours late..
any thoughts?
Thanks in advance
The server system is configured with the wrong timezone for your location. Fix that with date_default_timezone_set.
can change the timezone in php ini file also
e.g.
[Date]
; Defines the default timezone used by the date functions
date.timezone = "America/Los_Angeles"

mysql time and php time not the same

When I use current_timestamp with MySQL, I get the correct time, but when I use
$mysqldate = date( 'Y-m-d H:i:s' );
I get the date with with an hour delay (eg, 4:42 PM is 5:42 PM).
I understood that both function use the server's local time - can someone explain the difference?
Thanks.
The global system time will be set via the /etc/localtime file, which will be either a symlink or a copy of a zone file from /usr/share/zoneinfo/ on most systems. Applications will use this as their default.
PHP can override this in a couple different ways:
date.timezone in php.ini
setting the TZ environment variable, e.g. putenv("TZ=US/Central");
date_default_timezone_set function (in PHP >= 5.1.0)
MySQL can override this by running the following query immediately after connecting:
SET time_zone = 'US/Central'
There are php locale settings, it takes it from php.ini, not from system time
Maybe your PHP server thinks it's in a different time zone or it uses different locale and daylight saving time rules.

Categories