php时间类补充
<?
/*
*@author luhuijie
*时间类
*date:2010-12-3
*/
class time_{
private $_time;
private $_y;
private $_m;
private $_d;
private $_h;
private $_mi;
private $_s;
private $weekname=array("日","一","二","三","四","五","六");
public $err_message;
function __get($name){
return $this->$name;
}
function __set($name,$value){
$this->$name = $value;
}
function __construct(){
$this->_time =time();
$this->change();
}
function change($date=""){//格式是1908-09-80 12:00:01 或者是int数字日期格式。
if($date=="")$date = $this->_time;
if(is_Numeric($date)){
$datestr = date("Y-m-d h:i:s",$date);
}else{
$datestr = $date;
}
$timeall = explode(" ",trim($datestr));
$temp = explode("-",$timeall[0]);
$this->_y = ((int)$temp[0]);
$this->_m = ((int)$temp[1]);
$this->_d = ((int)$temp[2]);
if(count($timeall)>1){
$temp2 = explode(":",$timeall[1]);
$this->_h = $temp2[0];
$this->_mi = $temp2[1];
$this->_s = $temp2[2];
}else{
$this->_h = 12;
$this->_mi = 0;
$this->_s = 0;
}
$this->_time = mktime($thour,$tmini,$tsec,$tmonth,$tday,$tyear);
}
function getweek()
{
return "星期".$weekname[date("w",$this->_time)];
}
function get_date($type){
switch($type){
case 1:
return $this->_y."年".$this->_m."月".$this->_d."日".$this->_h."时".$this->_mi."分".$this->_s."秒";
break;
case 2:
return $this->_y."年".$this->_m."月".$this->_d."日";
break;
case 3:
return $this->_h."时".$this->_mi."分".$this->_s."秒";
break;
default:
return $this->_y."-".$this->_m."-".$this->_d;
break;
}
}
}
$tim = new time_();
echo $tim ->get_date("1");
?>