Location: PHPKode > scripts > IDDateTime > iddatetime/iddatetime.class.php
<?php

class IDDateTime {
	const _VER= '1.1'; //class version

	//convert seconds to something like 2:25:45 or 2d. 23:59:59
	static function SecToTime($sec) {
		$days = floor($sec / 86400);
			$sec = $sec - ($days * 86400);
		$hours = floor($sec / 3600);
			$sec = $sec - ($hours * 3600);
		$minutes = floor($sec / 60);
			$sec = $sec - ($minutes * 60);
		$seconds = $sec;
		
		if($days > 0) $days= $days.'d. '; else $days='';
		if ($minutes < 10) $minutes= '0'.$minutes;
		if ($seconds < 10) $seconds= '0'.$seconds;
		
		return $days.$hours.':'.$minutes.':'.$seconds;
	}
	
	//show timer on page, this function needs to later call AddTimerEngine for adding timer engine itself.
	static function ShowTimer($id,$sec,$href='') {
		return '<div id="'.$id.'">'.IDDateTime::SecToTime($sec).'</div><script type="text/javascript">updateTime("'.$id.'",'.$sec.',"'.$href.'");</script>';
	}
	
	//timer engine
	static function AddTimerEngine() {
		return '
		<script type="text/javascript">
		function updateTime(elementId,time,rdr) {
			var bt_obj = document.getElementById(elementId); 
			time--;
			var timeToEnd = time; 
			temp = timeToEnd;
			if(temp >= 0) { 
				days = Math.floor(temp / 86400);
				temp = temp % 86400;
				hours = Math.floor(temp / 3600);
				temp = temp % 3600; minutes = Math.floor(temp / 60);
				temp = temp % 60; output = "";
				seconds = temp;                
				if(days > 0) output = days + "d. "; 
				if(seconds < 10) seconds = "0" + seconds; 
				if(minutes < 10) minutes = "0" + minutes; 
				bt_obj.innerHTML = "<b>"+output+hours+":"+minutes+":"+seconds+"</b>"; 
				var jsExp = "updateTime(\'" + elementId + "\'," + time +",\'"+ rdr + "\')";
				setTimeout(jsExp , 1000); 
			} else {
				bt_obj.innerHTML = "DONE";
				window.location.href = rdr;
			}
		};
		</script>';
	}
	
	//convert seconds (unix time stamp) to "human" date and time
	static function DateTime($sec,$format='d-m-Y h:i:s') {
		return date($format,$sec);
	}

}
?>
Return current item: IDDateTime