Jump to content

Recommended Posts

Simple code:

<?php

// get the current hour (24 hour clock) and increase by 1
$n_hour = date('H')+1;

// Here we work out the hour, in 12 hour clock format
// we also set the am / pm of the hour
if($n_hour > 23)
{
    $n_hour = 12;
    $m = 'am';
}
elseif($n_hour > 11)
{
    $n_hour = date('g', mktime($n_hour));
    $m = 'pm';

}
else
{
    $m = 'am';
}

$c_mins = date('j');

$l_mins = 60 - $c_mins;

$time_left = 'There are ' . $l_mins . 'minutes left until ' . $n_hour . $m;

echo $time_left;

?>

 

Link to comment
https://forums.phpfreaks.com/topic/46405-php-countdown/#findComment-225681
Share on other sites

Add the following line to the top of script:

date_default_timezone_set('Europe/London');

 

<?php

date_default_timezone_set('Europe/London');

// get the current hour (24 hour clock) and increase by 1
$n_hour = date('H')+1;

// Here we work out the hour, in 12 hour clock format
// we also set the am / pm of the hour
if($n_hour > 23)
{
    $n_hour = date('g', mktime($n_hour));
    $m = 'am';
}
elseif($n_hour > 11)
{
    $n_hour = date('g', mktime($n_hour));
    $m = 'pm';

}
else
{
    $m = 'am';
}

// get the current minutes
$c_mins = date('i');

// take the current minutes from 60 (60 minutes in an hour)
$l_mins = 60 - $c_mins;

// Now we set up the message to be shown.
$time_left = 'There are ' . $l_mins . 'minutes left until ' . $n_hour . $m;

// echo the message we setup above
echo $time_left;

?>

 

Fixed it using:

putenv("TZ=Europe/London");

 

However the minutes are wrong, it says 50min to 12, when there are only 20.

I typed j instead i for the the date function when getting the current minutes. :D

 

That is corrected now.

Link to comment
https://forums.phpfreaks.com/topic/46405-php-countdown/#findComment-225691
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.