Page 1 of 1

Time with Timezone

Posted: Wed Jul 25, 2007 11:00 pm
by sarav_dude
Hi there,

I have a selection box in which a list of times are available like

1:00,
2:00,
......,
23:00,
00:00

and another select box with the timezones.

user selecting this time, timezone and it is stored in the DB.

Now, suppose if a user has selected 22:00 and time zone selected is (US/Alaska) how do i show this time in (Asia/Calcutta) ?

Also, as We know we can use the following

putenv('TZ=Asia/Calcutta');
echo date("h:i",time());

but how do i convert 22:00 to timestamp.

Thanks.

Posted: Wed Jul 25, 2007 11:18 pm
by superdezign

Posted: Wed Jul 25, 2007 11:23 pm
by sarav_dude
i have used mktime() already , it shows the same time in different environments

Posted: Wed Jul 25, 2007 11:27 pm
by superdezign
sarav_dude wrote:i have used mktime() already , it shows the same time in different environments
Use it to calculate the difference between the times, and then apply that difference to all time values.

Posted: Wed Jul 25, 2007 11:34 pm
by sarav_dude
Please read my question carefully ... i want this following working but it is not working :

Code: Select all

putenv('TZ=Africa/Harare');

$ts = mktime(22, 0, 0, date('n'), date('j'), date('Y')); 
echo date("h:i",$ts)."<br />";


putenv('TZ=Asia/Calcutta');
$ts = mktime(22, 0, 0, date('n'), date('j'), date('Y')); 
echo date("h:i",$ts)."<br />";

It should display the time according to that in different TZ variables.

Posted: Thu Jul 26, 2007 7:49 am
by miro_igov
I'm not sure if mktime() works well with the putenv the TZ, but if i was at your place i would use strtotime(), it works very well with TZ and you don't need to specify bunch of arguments, but just

Code: Select all

strtotime(date('Y-m-d H:i:s'));

Posted: Thu Jul 26, 2007 7:59 am
by sarav_dude
ok good , but how we can use this with this time 22:00 ,say i want to show 22:00 in two time zones then ?

Posted: Thu Jul 26, 2007 8:06 am
by miro_igov
Use the above example and do it yourself, we are not here to do any coding work, just give little help.

In order to display 22:00 in 2 time zones you need first to set the one timezone with putenv then execute strtotime which returns the result in variable, lets say $time_1, then run again putenv with the other time zone and again strtotime which returns the result in $time_2.

echo "Time zone 1:".$time_1.' Time zone 2: '.$time_2;

Posted: Thu Jul 26, 2007 8:08 am
by sarav_dude
Yes its great ... thats what i need thanks buddy u are awesome :D :D :D

Code: Select all

putenv('TZ=Asia/Calcutta');
$time=strtotime('22:00');
echo date("h:i:s a",$time);
putenv('TZ=Africa/Harare'); 
echo date("h:i:s a",$time);