...

View Full Version : Output current hour + 1



tomharto
08-23-2011, 09:24 PM
I need to output the current hour plus 1 (e.g. if the hour was 1pm it would output 2pm).

I current have

<?php echo date("H:i:s"); ?>
which outputs the current time, how would i increment it by an hour?

mlseim
08-23-2011, 09:39 PM
<?php echo date("H:i:s", mktime(date("H")+1, date("i"), date("s"), date("m"), date("d"), date("Y"))); ?>



Edit,
If this is a timezone issue, you can use PHP to switch timezones for your server.
http://php.net/manual/en/function.date-default-timezone-set.php

.

tomharto
08-23-2011, 09:49 PM
What it is is im outputting timezoens e.g. GMT 0 GMT +1 GMT +2 etc. Perhaps theres a better way of doing this what i didnt think of?

bcarl314
08-23-2011, 09:57 PM
<?php echo date("H:i:s", mktime(date("H")+1, date("i"), date("s"), date("m"), date("d"), date("Y"))); ?>



Edit,
If this is a timezone issue, you can use PHP to switch timezones for your server.
http://php.net/manual/en/function.date-default-timezone-set.php

.

Or perhaps:



<?php
echo date("H:i:s",mktime()+3600); //3600 seconds = 1 hour.
?>

kbluhm
08-23-2011, 10:08 PM
Another solution:


date( 'H:i:s', strtotime( '+1 hour' ) )

tomharto
08-23-2011, 10:09 PM
Thanks, all those work fine :)

mlseim
08-23-2011, 11:42 PM
With date_default_timezone_set you specify a city within the timezone.
There is a specific list of cities to choose from. Once you set that, all
date functions after that (in the same script) will be using your timezone
for all calculations.

So, if you ask the user to pick a city from a list, you could set it that way too.

I live near St. Paul, Minnesota ...
So I would pick this timezone for me ...

<?php
date_default_timezone_set('America/Chicago');

The main reason I do that is, my webhost server is on the East Coast,
so their time is one hour ahead of me. I always force them to use my timezone
if I'm concerned about specific hours within dates.


.

tomharto
08-24-2011, 02:39 AM
Ive set the timezone to my localtime, however im outputting a GMT timelist eg GMT +0 = hh:mm, GMT +1 = HH:MM etc so i needed to increment the time by one hour :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum