- Joined
- Apr 13, 2011
- Messages
- 386
- Reaction score
- 69
Can anyone please help me with an countdown time that can be seted to start at time and end at another time two time a day?
Regards.
Regards.
<html>
<head>
<script type="text/javascript">
var num = number of seconds;
var timer;
function countdown() {
num--;
document.getElementById('countdown_ele').innerHTML = num;
if(num < 1){
clearTimeout(timer);
}
}
function init() {
document.getElementById('countdown_ele').innerHTML = num;
timer = setInterval("countdown()",1000);
}
</script>
</head>
<body onload="init();">
<span id="countdown_ele"></span>
</body>
</html>
<? /*
declare target date; source: http://us.imdb.com/ReleaseDates?0121766 ;
*/
$day = 31; // Day of the countdown
$month = 12; // Month of the countdown
$year = 2012; // Year of the countdown
$hour = 23; // Hour of the day (east coast time)
$event = "New Year's Eve, 2012"; //event
$calculation = ((mktime ($hour,0,0,$month,$day,$year) - time(void))/3600);
$hours = (int)$calculation;
$days = (int)($hours/24);
/*
mktime() http://www.php.net/manual/en/function.mktime.php
time() http://www.php.net/manual/en/function.time.php
(int) http://www.php.net/manual/en/language.types.integer.php
*/
?>
<ul>
<li>The date is <?=(date ("l, jS \of F Y g:i:s A"));?>.</li>
<li>It is <?=$days?> days until <?=$event?>.</li>
<li>It is <?=$hours?> hours until <?=$event?>.</li>
</ul>
PHP:<? /* declare target date; source: http://us.imdb.com/ReleaseDates?0121766 ; */ $day = 31; // Day of the countdown $month = 12; // Month of the countdown $year = 2012; // Year of the countdown $hour = 23; // Hour of the day (east coast time) $event = "New Year's Eve, 2012"; //event $calculation = ((mktime ($hour,0,0,$month,$day,$year) - time(void))/3600); $hours = (int)$calculation; $days = (int)($hours/24); /* mktime() http://www.php.net/manual/en/function.mktime.php time() http://www.php.net/manual/en/function.time.php (int) http://www.php.net/manual/en/language.types.integer.php */ ?> <ul> <li>The date is <?=(date ("l, jS \of F Y g:i:s A"));?>.</li> <li>It is <?=$days?> days until <?=$event?>.</li> <li>It is <?=$hours?> hours until <?=$event?>.</li> </ul>
feel free to modify for your needs
Error:
Problem at line 1 character 11: 'number' was used before it was defined.
var num = number of seconds;
Problem at line 1 character 17: Expected ';' and instead saw 'of'.
var num = number of seconds;
Problem at line 1 character 18: Expected 'of' at column 1, not column 18.
var num = number of seconds;
Problem at line 1 character 18: 'of' was used before it was defined.
var num = number of seconds;
Problem at line 1 character 18: Expected an assignment or function call and instead saw an expression.
var num = number of seconds;
Problem at line 1 character 20: Expected ';' and instead saw 'seconds'.
var num = number of seconds;
Problem at line 1 character 21: Expected 'seconds' at column 1, not column 21.
var num = number of seconds;
Problem at line 1 character 21: 'seconds' was used before it was defined.
var num = number of seconds;
Problem at line 1 character 21: Expected an assignment or function call and instead saw an expression.
var num = number of seconds;
Problem at line 2 character 7: Expected 'var' at column 1, not column 7.
var timer;
Problem at line 3 character 7: Expected 'function' at column 1, not column 7.
function countdown() {
Problem at line 4 character 9: Missing 'use strict' statement.
num--;
Problem at line 4 character 9: Expected 'num' at column 5, not column 9.
num--;
Problem at line 4 character 12: Unexpected '--'.
num--;
Problem at line 5 character 9: Expected 'document' at column 5, not column 9.
document.getElementById('countdown_ele').innerHTML = num;
Problem at line 5 character 9: 'document' was used before it was defined.
document.getElementById('countdown_ele').innerHTML = num;
Problem at line 6 character 9: Expected 'if' at column 5, not column 9.
if(num < 1){
Problem at line 6 character 11: Expected exactly one space between 'if' and '('.
if(num < 1){
Problem at line 6 character 20: Expected exactly one space between ')' and '{'.
if(num < 1){
Problem at line 6 character 20: Missing space between ')' and '{'.
if(num < 1){
Problem at line 7 character 11: Expected 'clearTimeout' at column 9, not column 11.
clearTimeout(timer);
Problem at line 7 character 11: 'clearTimeout' was used before it was defined.
clearTimeout(timer);
Problem at line 8 character 9: Expected '}' at column 5, not column 9.
}
Problem at line 9 character 7: Expected '}' at column 1, not column 7.
}
Problem at line 10 character 7: Expected 'function' at column 1, not column 7.
function init() {
Problem at line 11 character 9: Missing 'use strict' statement.
document.getElementById('countdown_ele').innerHTML = num;
Problem at line 11 character 9: Expected 'document' at column 5, not column 9.
document.getElementById('countdown_ele').innerHTML = num;
Problem at line 11 character 9: 'document' was used before it was defined.
document.getElementById('countdown_ele').innerHTML = num;
Problem at line 12 character 9: Expected 'timer' at column 5, not column 9.
timer = setInterval("countdown()",1000);
Problem at line 12 character 17: 'setInterval' was used before it was defined.
timer = setInterval("countdown()",1000);
Problem at line 12 character 43: Missing space between ',' and '1000'.
timer = setInterval("countdown()",1000);
Problem at line 12 character 17: Implied eval is evil. Pass a function instead of a string.
timer = setInterval("countdown()",1000);
Problem at line 13 character 7: Expected '}' at column 1, not column 7.
}
Undefined variable: document 3 countdown, clearTimeout 3 countdown, document 10 init, setInterval 10 init
Global countdown, init, num, number, of, seconds, timer
3 countdown()
Global num, timer
10 init()
Global num, timer
/*properties
getElementById, innerHTML
*/
var now = new Date(), to = <some Date>;
if (to - now >= 0) {
// it is now the desired date or later
} else {
// it is not
}
DST support, also setTimeout is not a high-precision timer, so don't use it that way.
In JS:
Code:var now = new Date(), to = <some Date>; if (to - now >= 0) { // it is now the desired date or later } else { // it is not }
if ($current_time <= $max_time && $current_time >= $min_time) {
//if between the min and max times
} else {
// not in between min and max times.
}
One last question.
How do i define current time and max and min time.
$max_time = strtotime('tomorrow');
$current_time = strtotime('today');
$min_time = strtotime('yesterday');
$max_time = strtotime('-1 hour'); // 1 hour ago
$current_time = strtotime('2 hours ago'); // 2 hours ago
$min_time = strtotime('180 minutes ago'); // 180m / 60m = 3h ago