시작 날짜가있는 기간 목록을 반환하는 JSON REST 서비스가 있습니다. 어떻게 시작 날짜를 javascript 날짜로 변환 할 수 있습니까?각도를 사용하여 자바 스크립트 날짜로 json 응답의 일부를 변환하는 방법?
내 서비스 정의에 내가 ngResource을 사용하고[ {
"periodId": 1234,
"startDate": [ 2011, 12, 24]
},
{
"periodId": 5678,
"startDate": [ 2012, 12, 24]
}
]
:
angular.module('periodservice',['ngResource']).
factory('Periods', function($resource) {
return $resource('../rest/periods', {}, {
query : {method : 'GET', params : {}, isArray : true}
});
});
컨트롤러는 매우 정직하고 있습니다.
function EksternVareRedigeringCtrl ($scope, Periods){
$scope.periods = Periods.query(function(success, status, headers){
$scope.msgf = success;
console.log("this is the succsess);
}, function(errors){
$scope.msgf = errors;
console.log("This is an error....." + ' ' + $scope.msgf.status);
});
}
은 지금은 적절한 날짜로 변환하는 대신 이런 식으로 날짜를 표시 :
new Date(period.startDate[0], period.startDate[1]-1, period.startDate[2])
주 나는 때문에 period.startDate[1]-1
을 사용했습니다 :
<div class="period">Period: {{period[0]}}-{{period[1]}}-{{period[2]}}</div>
[시작일]은 [년, 월, 일] 형식입니까? ('2012,24,14'은 유효한 날짜가 아닙니다 =)) – bmleite
죄송합니다. 오타였습니다. 사실이 형식 [2012, 12, 24]입니다. 예제가 업데이트되었습니다. :-) – thomasfl
$ scope.periodDate = function (마침표) {return new Date (period.startDate)} – thomasfl