获取本周第一天/最后一天、本月第一天/最后一天的时间戳
程序员文章站
2023-02-28 13:54:09
/**
* 获取本周第一天/最后一天的时间戳
* @param string $type
* @return integer
*/
pu...
/** * 获取本周第一天/最后一天的时间戳 * @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; } }
上一篇: 淘宝店如何开到微信上 手把手教你开微店