Time with Timezone
Moderator: General Moderators
- sarav_dude
- Forum Newbie
- Posts: 24
- Joined: Sun Apr 30, 2006 8:40 am
- Location: India
- Contact:
Time with Timezone
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.
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.
- sarav_dude
- Forum Newbie
- Posts: 24
- Joined: Sun Apr 30, 2006 8:40 am
- Location: India
- Contact:
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- sarav_dude
- Forum Newbie
- Posts: 24
- Joined: Sun Apr 30, 2006 8:40 am
- Location: India
- Contact:
Please read my question carefully ... i want this following working but it is not working :
It should display the time according to that in different TZ variables.
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.
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'));- sarav_dude
- Forum Newbie
- Posts: 24
- Joined: Sun Apr 30, 2006 8:40 am
- Location: India
- Contact:
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;
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;
- sarav_dude
- Forum Newbie
- Posts: 24
- Joined: Sun Apr 30, 2006 8:40 am
- Location: India
- Contact:
Yes its great ... thats what i need thanks buddy u are awesome
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);