我需要获得给定的月份开始日期和结束日期。
var currentDate = new Date();
var currentMonth = currentDate.getMonth();
Run Code Online (Sandbox Code Playgroud)
尝试这个:
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 ;
}
Run Code Online (Sandbox Code Playgroud)
和:
<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>
Run Code Online (Sandbox Code Playgroud)