|
-
Aug 8th, 2002, 09:13 AM
#1
Thread Starter
Hyperactive Member
Plus or minus hours
I use this code to print time
$Time=date("G:i A");
echo $Time;
output (for example):
20:51 PM
the problem that hour in my country is 18:51 PM .. so how can I minus 2 hour from day.
Thanks
-
Aug 8th, 2002, 09:59 AM
#2
Addicted Member
Its kinda tricky but off hand this is all I can think of.
$Time=date("G:i A");
//substring out the hour and minute from your inital function
$TimeToken = explode(":", $Time);
$subHour = $TimeToken[0];
$subMinute = substr($TimeToken[1], 0, 2);
//add it to the mktime function -2 on the hour
mktime function on php.net
$makeTime = mktime ( $subHour -2,$subMinute,0,1,1,2002);
//use the date function on $makeTime
$grabTime = date("G:i A", $makeTime);
echo("<BR>".$grabTime);
That should do it the long way... you might want to check out the localtime function too... that may be where you want to go
localtime function on php.net
-
Aug 19th, 2002, 03:22 PM
#3
Stuck in the 80s
Does anyone know of a shorter way to do this or is this about it?
-
Aug 19th, 2002, 03:59 PM
#4
Stuck in the 80s
I found a better way. Just convert it to a timestamp and subtract or add 3600 (which is equal to an hour)
-
Aug 20th, 2002, 04:49 AM
#5
Thread Starter
Hyperactive Member
And I found very Better way
use that:
$GMT="-2";
echo date ("G:i A",mktime (date("G")+$GMT,date("i"),date("s"),date("m"),date("d"),date("Y")));
-
Aug 20th, 2002, 09:31 AM
#6
Stuck in the 80s
Originally posted by prokhaled
And I found very Better way
use that:
$GMT="-2";
echo date ("G:i A",mktime (date("G")+$GMT,date("i"),date("s"),date("m"),date("d"),date("Y")));
For some reason, I think this way is much prettier:
Code:
$time = date("G:i A", strtotime(date("G:i A")) - 7200);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|