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:

Thats cool

Post by sarav_dude »

volka wrote: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
Yes that was cool, it works perfectly thank you very much ....i have used now

Code: Select all

date_default_timezone_set('Asia/Calcutta');
and its perfect, thats what i m searching for.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Maybe you're allowed to change the value via .htaccess. But that depends on your provider.
The line

Code: Select all

php_value date.timezone Asia/Calcutta
would set date.timezone=Asia/Calcutta for all scripts in that directory and all sub-directories.
If you have many scripts that rely on the timezone setting you'd better ask your provider wether you can use htaccess for this or not.
On the other hand there's nothing wrong 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 »

Thats a very good idea , i will ask the hosting personnel about the use for htaccess, i guess it is allowable , thank you very much :D
Post Reply