当前位置:编程学习 > php >>

原创处理时间的类,请大家指正

答案:timer.class.php
<?
//###################### Start Introduce #######################################
// author: bluemaple ; email: bluemaple@x263.net
// 最后修改时间2002-1-28 1:35
// 此函数求解决返回时间显示格式问题。包括date()函数的所有格式,默认的$type为最常用的类型
// 除了$year,$month,$day,$hour,$minute,$second;添加了$week(周),$zone(一年中的第几天),$numMonth(当前月份的天数)
// 其中默认的都为最常用的格式
// 特点,在时间处理中用得最多的是mktime,这里设置mktime可以按照习惯输入(年,月,日)显示
// mktimeY();mktimeW();mktimeM();mktimeD();可以方便设置一个时间相隔y年,n月,在mysql检索中方便使用
// subTime();函数可以方便求得两个时间相差的天数,周等
//####################### End Introduce ########################################

class TIMER{
  var $year;   // 年
  var $month;  // 月
  var $day;    // 日
  var $hour;   // 时
  var $minute; // 分
  var $second; // 秒
  var $week;   // 周
  var $zone;   // 一年中的第几天
  var $numMonth; // 当前月份的天数
  var $mktime;  // mktime
     
  function year($time="",$type=0){ // 返回年
                                   // $type=0表示返回四位的年份
                                   // $type=1表示返回二位的年份
      if($time=="") $time=time();
      if($type==0) $this->year=date("Y",$time);
      if($type==1) $this->year=date("y",$time);
      return $this->year;
       }    
      
  function month($time="",$type=0){ // 返回月
                                    // $type=0表示返回1~12
                                    // $type=1表示返回01~12
                                    // $type=2表示返回jan..三个英文字母
                                    // $type=3表示返回英语全名
      if($time=="") $time=time();
      if($type==0) $this->month=date("n",$time);
      if($type==1) $this->month=date("m",$time);
      if($type==2) $this->month=date("M",$time);
      if($type==3) $this->month=date("F",$time);
      return $this->month;
      }   
      
  function day($time="",$type=0){ // 返回日
                                  // $type=0返回1~31
                                  // $type=1返回01~31
      if($time=="") $time=time();
      if($type==0) $this->day=date("j",$time);
      if($type==1) $this->day=date("d",$time);
      return $this->day;
      }    

  function hour($time="",$type=0){ // 返回时
                                   // $type=0返回1~24
                                   // $type=1返回1~12
                                   // $type=2返回01~24
                                   // $type=3返回01~12
      if($time=="") $time=time();
      if($type==0) $this->hour=date("H",$time);
      if($type==1) $this->hour=date("h",$time);
      if($type==2) $this->hour=date("G",$time);
      if($type==3) $this->hour=date("g",$time);
      return $this->hour;
      }    
      
  function minute($time="",$type=0){ // 返回分
      if($time=="") $time=time();
      if($type==0) $this->minute=date("i",$time);
      return $this->minute;
    }
   
  function second($time="",$type=0){ // 返回秒
                                     // $type=0 返回1~59
                                     // $type=1 返回字尾加英文序数,二个英文字母
      if($time=="") $time=time();
      if($type==0) $this->second=date("s",$time);
      if($type==1) $this->second=date("S",$time);
      return $this->second;
      }
  
  function week($time="",$type=0){ // 返回周
                 

上一个:星期的计算函数
下一个:转:编写自己的php扩展函数

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,