Search code examples
phpcentos

Echoing time from now and one hour later


Here I have set the my Centos time Zone.> sudo hwclock – show

Tue 04 Feb 2014 10:23:10 AM AFT  -0.596389 seconds
asia/kabul

Now on PHP I want to echo from 10:23:10 AM to 11:23:10 AM

Here I have set my code for the echoing.

<? echo (date('G', time())+5) ;
echo(':00 To ');
echo (date('G', time())+6);
echo(':00');  ?>

Now as result of my above echoing PHP code I get the result of

15:00 To 16:00

But instead I want to get the echo of below or as what ever my HTTP server time is from NOW to 1 hour next.

10:23:10 AM to 11:23:10 AM

Solution

  • Add to the time and then print the date.

    echo date('G',time()+3600);
    

    time() returns number of seconds since the unix epoch, then you add 3600 seconds for 1 hour and you use that in your date.