1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
functionaweek( $gdate = "" , $first = 0){
if (! $gdate ) $gdate = date ( "Y-m-d" );
$w = date ( "w" , strtotime ( $gdate ));
$dn = $w ? $w - $first : 6;
$st = date ( "Y-m-d" , strtotime ( "$gdate -" . $dn . " days" ));
$en = date ( "Y-m-d" , strtotime ( "$st +6 days" ));
$last_st = date ( 'Y-m-d' , strtotime ( "$st - 7 days" ));
$last_en = date ( 'Y-m-d' , strtotime ( "$st - 1 days" ));
returnarray( $st , $en , $last_st , $last_en );
}
echoimplode( "|" , aweek( "" , 1)). '<br />' ;
echo '本周第一天(星期日为一周开始):' . date ( 'Y-m-d' , time()-86400* date ( 'w' )). '<hr>' ;
echo '本周第一天(星期一为一周开始):' . date ( 'Y-m-d' , time()-86400* date ( 'w' )+( date ( 'w' )>0?86400:-6*86400)). '<hr>' ;
echo '本月第一天:' . date ( 'Y-m-d' , mktime (0,0,0, date ( 'm' ),1, date ( 'Y' ))). '<hr>' ;
echo '本月最后一天:' . date ( 'Y-m-d' , mktime (0,0,0, date ( 'm' ), date ( 't' ), date ( 'Y' ))). '<hr>' ;
$m = date ( 'Y-m-d' , mktime (0,0,0, date ( 'm' )-1,1, date ( 'Y' )));
$t = date ( 't' , strtotime ( "$m" ));
echo '上月第一天:' . date ( 'Y-m-d' , mktime (0,0,0, date ( 'm' )-1,1, date ( 'Y' ))). '<hr>' ;
echo '上月最后一天:' . date ( 'Y-m-d' , mktime (0,0,0, date ( 'm' )-1, $t , date ( 'Y' ))). '<hr>' ;
|