<?php$future_date = '02/19/2025 10:1 AM'; ?> <script> var end = new Date('<?php echo $future_date;?>');var _second = 1000; var _minute = _second * 60; var _hour = _minute * 60; var _day = _hour * 24; var timer;function showRemaining() { var now = new Date(); var distance = end - now; if (distance < 0) {clearInterval(timer); document.getElementById('countdown').innerHTML = 'EXPIRED!';return; } var days = Math.floor(distance / _day); var hours = Math.floor((distance % _day) / _hour); var minutes = Math.floor((distance % _hour) / _minute); var seconds = Math.floor((distance % _minute) / _second);document.getElementById('countdown').innerHTML = days + ' days '; document.getElementById('countdown').innerHTML += hours + ' hrs '; document.getElementById('countdown').innerHTML += minutes + ' mins '; document.getElementById('countdown').innerHTML += seconds + ' secs'; }timer = setInterval(showRemaining, 1000); </script> <div id="countdown"></div>
Tuesday, December 30, 2014
Countdown Javascript + PHP
Validasi jarak tanggal
<?php
$string = '2014-12-30 11:00 PM - 2015-01-29 11:59 AM';
$string = '2014-12-30 11:00 PM - 2015-01-29 11:59 AM';
public function _check_date_range($string){
if(strpos($string," - ")){
$d = explode(" - ", $string);
$d1 = date_format(date_create_from_format('Y-m-d h:i A', $d[0]),'Y-m-d H:i:s');
$d2 = date_format(date_create_from_format('Y-m-d h:i A', $d[1]),'Y-m-d H:i:s');
if($d1 && $d2){
return true;
}else{
$this->form_validation->set_message('_check_date_range', $d1);
return false;
}
}else{
$this->form_validation->set_message('_check_date_range', 'The %s field does not contain - ');
return false;
}
}
?>
?>
set_message($input_name,$message);
<?php
public function username_check($str){
if ($str == 'test'){
$this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
return FALSE;
}else{
return TRUE;
}
}
?>
checkdate() ( Pemeriksaan tanggal )
<?php
$year = 2000;
$date = 31;
$month = 12;
if(checkdate($month, $date, $year)){
echo "TRUE";
}
?>
$year = 2000;
$date = 31;
$month = 12;
if(checkdate($month, $date, $year)){
echo "TRUE";
}
?>