如何在javascript中获得月份开始日期和结束日期

时间:2015-03-19 14:33:33

标签: javascript

我需要获得月份开始日期和结束日期。

   var currentDate = new Date();
   var currentMonth = currentDate.getMonth();

1 个答案:

答案 0 :(得分:3)

试试这个:

function MyCtrl($scope){
   var date = new Date(), year = date.getFullYear(), month = date.getMonth();
   var firstDay = new Date(year, month, 1);
   var lastDay = new Date(year, month + 1, 0);
   $scope.firstDay = firstDay ;
   $scope.lastDay = lastDay ;
   $scope.date = date ;    
}

<div ng-app ng-controller="MyCtrl">
<ul>
    <li>{{date | date:'yyyy-MM-dd'}}</li> 
    <li>{{firstDay | date:'yyyy-MM-dd'}}</li> 
    <li>{{lastDay | date:'yyyy-MM-dd'}}</li> 
</ul>