萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> 計算當前日期是一年中的第幾周

計算當前日期是一年中的第幾周

 代碼如下 復制代碼   function mathweek( $date )
  {
    $first_day_week = date( "n" , mktime ( 0 , 0 , 0 , 1 , 1 , date( 'y' , $date ) ) );
    $first_week_days = 7 - $first_day_week + 1;
    $day_index = date( "z" , $date ) + 1 - $first_week_days ;
    $day_index = $day_index ? $day_index : 0 ;
    return ceil($day_index/7) + 1;
  }
       
       $date = strtotime('2010-08-12');
       echo mathweek($date);
?>

asp教程.net計算方法

 代碼如下 復制代碼 system.globalization.gregoriancalendar   gc   =   new   system.globalization.gregoriancalendar();
int   weekofyear   =   gc.getweekofyear(datetime.now,   system.globalization.calendarweekrule.firstday,   dayofweek.monday);

 

copyright © 萬盛學電腦網 all rights reserved