知识屋:更实用的电脑技术知识网站
所在位置:首页 > 编程技术  > PHP编程

获取本周第一天/最后一天、本月第一天/最后一天的时间戳

发表时间:2014-09-05来源:网络

/**   * 获取本周第一天/最后一天的时间戳   * @param string $type   * @return integer   */   public function get_week_time( $type = 'first' ) {       /* 获取本周第一天/最后一天的时间戳 */       $year = date( "Y" );       $month = date( "m" );       $day = date( 'w' );       $nowMonthDay = date( "t" );       if ( $type == 'first' ) {           $firstday = date( 'd' ) - $day;           if ( substr( $firstday, 0, 1 ) == "-" ) {               $firstMonth = $month - 1;               $lastMonthDay = date( "t", $firstMonth );               $firstday = $lastMonthDay - substr( $firstday, 1 );               $time_1 = strtotime( $year . "-" . $firstMonth . "-" . $firstday );           } else {               $time_1 = strtotime( $year . "-" . $month . "-" . $firstday );           }           return $time_1;       } else {           $lastday = date( 'd' ) + (7 - $day);           if ( $lastday > $nowMonthDay ) {               $lastday = $lastday - $nowMonthDay;               $lastMonth = $month + 1;               $time_2 = strtotime( $year . "-" . $lastMonth . "-" . $lastday );           } else {               $time_2 = strtotime( $year . "-" . $month . "-" . $lastday );           }           return $time_2;       }   }    /**   * 获取本月第一天/最后一天的时间戳   * @param string $type   * @return integer   */   public function get_month_time( $type = 'first' ) {       /* 获取本月第一天/最后一天的时间戳 */       $year = date( "Y" );       $month = date( "m" );       $allday = date( "t" );       if ( $type == 'first' ) {           $start_time = strtotime( $year . "-" . $month . "-1" );           return $start_time;       } else {           $end_time = strtotime( $year . "-" . $month . "-" . $allday );           return $end_time;       }   }  

 

(免责声明:文章内容如涉及作品内容、版权和其它问题,请及时与我们联系,我们将在第一时间删除内容,文章内容仅供参考)
收藏
  • 人气文章
  • 最新文章
  • 下载排行榜
  • 热门排行榜