Time not displaying properly with php 5.1.2

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

Post by sarav_dude »

volka wrote:I stand corrected.
aaronhall wrote:Try adjusting the date.timezone directive in php.ini (http://www.php.net/manual/en/ref.dateti ... e.timezone)
You should do that instead of fiddeling with the timestamp.

Code: Select all

<?php echo get_cfg_var('cfg_file_path'); ?>
tells you which php.ini you have to change.
Don't forget to restart the webserver after changing the php.ini
hi , it just echos : the path of the php.ini file, it shows : D:/windows/php.ini
User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

php bug

Post by sarav_dude »

just check this link :

http://bugs.php.net/bug.php?id=34475&edit=1

its a bug.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Just because someone cries bug it's not necessarily a bug
http://bugs.php.net/bug.php?id=34475 wrote:Status: Bogus
Version: 5.1.0RC2
sarav_dude wrote:hi , it just echos : the path of the php.ini file, it shows : D:/windows/php.ini
As stated that's the php.ini you have to change.
Last edited by volka on Wed May 02, 2007 2:08 am, edited 2 times in total.
User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

I found the solution my problem

Post by sarav_dude »

I found the solution my problem, just setting the timezone to

Code: Select all

date_default_timezone_set('Indian/Cocos');
and subtracting one hour from that to display the correct time .
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

If you write the timezone to the php.ini as described in http://www.php.net/manual/en/ref.dateti ... e.timezone you don't have to call date_default_timezone_set() in each and every script.
If you still need to add an extra hour it's either the wrong timezone or the zoneinfo of your os needs an update.
User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

Post by sarav_dude »

Yes you are right , may be some kind of update needed to my os as well as php, also i have checked the link given by you , it is good, but i was unable to find the settings mention on that page in my php.ini file , may be php needs an update, all the following settings are not present in my php.ini.

Code: Select all

date.default_latitude	
date.default_longitude
date.sunrise_zenith	
date.sunset_zenith	
date.timezone
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Add them as you need them. If a parameter is missing from php.ini its default value is used
date.timezone was introduced in php 5.1.0, just add the line date.timezone = 'Indian/Cocos' to D:/windows/php.ini, then restart the webserver.

When I run

Code: Select all

<?php
$timestamp = time();

echo "<pre>\n";
echo 'timestamp: ', $timestamp, "\n";
foreach( array('UTC', 'Europe/Berlin', 'Indian/Cocos') as $tz ) {
	date_default_timezone_set($tz) or die('date_default_timezone_set('.$tz.') failed');
	echo date("H:i:s T = \U\T\CO", $timestamp), "\n";
}
echo "\n</pre>";
?>
it prints
timestamp: 1178090884
07:28:04 UTC = UTC+0000
09:28:04 CEST = UTC+0200
13:58:04 CCT = UTC+0630
is it about 2pm where you're living?
User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

Post by sarav_dude »

ok i will add and check what it displays, also it is 1:05 pm as per indian timings.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Do you live on Cocos (Keeling) Islands?
User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

Post by sarav_dude »

yes , i have just set

Code: Select all

ini_set("date.timezone","Indian/Cocos");
, and it is working fine now, thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

No need for ini_set, just put in in the php.ini. Otherwise you have to call ini_set() in each and every script just like with date_default_timezone_set()
User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

Post by sarav_dude »

no sir , i live in india and as i mentioned before there is one hour difference with the setting "Indian/Cocos", so i subtract one hour to display the correct time.

yes i have put the settings in the php.ini file in my local system, but for my online site i have to use ini_set because i guess hosting server which is in USA wont allow to change their ini settings ...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I probably misunderstood
volka wrote:Do you live on Cocos (Keeling) Islands?
sarav_dude wrote:yes , i have just set

Code: Select all

ini_set("date.timezone","Indian/Cocos");
, and it is working fine now, thanks
Let me ask you again: Do you live on Cocos (Keeling) Islands?
Do you want the time settings for Cocos (Keeling) Islands?


Cocos (Keeling) Islands is in the timezone UTC+06:30
UTC currently is 08:12:01 <-> it's 14:42:01 on Cocos (Keeling) Islands
User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

Post by sarav_dude »

volka wrote:I probably misunderstood
volka wrote:Do you live on Cocos (Keeling) Islands?
sarav_dude wrote:yes , i have just set

Code: Select all

ini_set("date.timezone","Indian/Cocos");
, and it is working fine now, thanks
Let me ask you again: Do you live on Cocos (Keeling) Islands?
Do you want the time settings for Cocos (Keeling) Islands?


Cocos (Keeling) Islands is in the timezone UTC+06:30
UTC currently is 08:12:01 <-> it's 14:42:01 on Cocos (Keeling) Islands
sorry i forget to mentioned that i have search for timezone for the indian timings but i did not found that , so i used the one "indian/cocos" as it is closer to the indian timings what i needed , the "indian/cocos" timings are 2:49 pm and indian timings are 1:49 pm , so i subtract one hour from it to display the correct timings
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Asia/Calcutta and Asia/Colombo might be suitable, both have an offset of 19800 (seconds=5,5hours) and no daylight saving time.

Code: Select all

<?php
$timestamp = time();

echo "<pre>\n";
echo 'timestamp: ', $timestamp, "\n";
$zones = array(
		'Asia/Calcutta',
		'Asia/Colombo'
	);



foreach( $zones as $tz ) {
	date_default_timezone_set($tz) or die('date_default_timezone_set('.$tz.') failed');
	echo date("H:i:s T = \U\T\CO", $timestamp), "\n";
}
echo "\n</pre>";
?>
timestamp: 1178095755
14:19:15 IST = UTC+0530
14:19:15 IST = UTC+0530
Post Reply