Jump to content

[SOLVED] Need help with 4hour countdown script


ILYAS415

Recommended Posts

Okay ive needed help on this before and now i need help on it again. Apparentley the person who made it b4 made a mistake somewhere. Basically wat this script is meant to do is count down every 4 hours starting from 00:00am in the morning. Okay i havnt had time to evaluate the script properly but these are 2 possible things that i think are wrong:

• The script is counting down from 01:00am instead of 12:00am

OR the script is counting down every 5 hours.

 

Heres the script:

<?php

$hours = intval(gmdate('h'));
$minutes =  intval(gmdate('i'));
$seconds =  intval(gmdate('s'));

$hours_left = (4 - ($hours % 4)) - (($minutes)?1:0);

$minutes_left = ($minutes)?((60 - $minutes)-(($seconds)?1:0)):0;
$minutes_left = str_pad ($minutes_left , 2, '0', STR_PAD_LEFT);

$seconds_left = ($seconds)?(60 - $seconds):0;
$seconds_left = str_pad ($seconds_left , 2, '0', STR_PAD_LEFT);

$hours_left= $hours_left;

echo 'Next reset in: '.$hours_left.'h '.$minutes_left.'m '.$seconds_left.'s<br><br>';

?>

Link to comment
Share on other sites

The script works perfectly. It doesn't start from a certain time, it just checks to see how much time is left before the hour is divisible by 4. The reason it isn't working for you is because it is using Greenwich Mean Time and you aren't. To fix this, change these three lines from:

$hours = intval(gmdate('h'));
$minutes =  intval(gmdate('i'));
$seconds =  intval(gmdate('s'));

 

to:

$hours = intval(date('h'));
$minutes =  intval(date('i'));
$seconds =  intval(date('s'));
[/code[

Link to comment
Share on other sites

I just copy and pasted the code. Unchanged it is one hour off. Using date() instead of gmdate(), it works perfectly. If it isn't working for you, you could simply change the original code on this line:

$hours = intval(gmdate('h'));

 

to:

$hours = intval(gmdate('h'))+1;

 

That should countdown to an hour divisible by four.

Link to comment
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.