当前位置: 移动技术网 > IT编程>开发语言>PHP > 获取本周第一天/最后一天、本月第一天/最后一天的时间戳

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

2018年03月23日  | 移动技术网IT编程  | 我要评论
/** 
  * 获取本周第一天/最后一天的时间戳 
  * @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;  
     }  
 }  

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网