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
Printable View
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
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
Does anyone know of a shorter way to do this or is this about it?
I found a better way. Just convert it to a timestamp and subtract or add 3600 (which is equal to an hour)
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:Quote:
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")));
Code:$time = date("G:i A", strtotime(date("G:i A")) - 7200);