JavaScript-过去12个月的列表
我有一个Angualr服务,列出从当前月份开始的12个月和一年: JS: 我如何修改此项以同时显示日期,以便:JavaScript-过去12个月的列表,javascript,angularjs,Javascript,Angularjs,我有一个Angualr服务,列出从当前月份开始的12个月和一年: JS: 我如何修改此项以同时显示日期,以便: 21 Oct 2014, 21 Sep 2014, 21 Aug 2014 etc etc 您只需将日期连接到月数组中的字符串: 因此,与此相反: months.push(monthNames[date.getMonth()] + ' ' + date.getFullYear()); 这样做: months.push(date.getDate() + ' ' + monthName
21 Oct 2014, 21 Sep 2014, 21 Aug 2014 etc etc
您只需将日期连接到月数组中的字符串: 因此,与此相反:
months.push(monthNames[date.getMonth()] + ' ' + date.getFullYear());
这样做:
months.push(date.getDate() + ' ' + monthNames[date.getMonth()] + ' ' + date.getFullYear());
将日期附加到字符串:
app.factory('12months', function() {
return {
getMonths: function() {
var date = new Date();
var months = [],
monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
for(var i = 0; i < 12; i++) {
months.push(date.getDate()+ ' ' +monthNames[date.getMonth()] + ' ' + date.getFullYear());
}
return months;
}
};
});
您可以在jquery中输入日期
var date = new Date();
date.getDate() //output:- 21
在天数数组中添加总天数:
app.factory('twelvemonths', function() {
return {
getMonths: function() {
var date = new Date();
var months = [],
monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
days=[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];
for(var i = 0; i < 12; i++) {
months.push(days[date.getDate()]+ ' ' +monthNames[date.getMonth()] + ' ' + date.getFullYear());
}
return months;
}
};
}) 如果要使用函数,可以将行更改为
months.push(date.getDate() + ' ' monthNames[date.getMonth()] + ' ' + date.getFullYear());
用电脑怎么样
var app=角度。模块“我的应用程序”[],函数{
}
app.controller'AppController',['$scope','12个月',
功能$scope,t个月{
$scope.tmmonths=tmmonths.getMonths;
}
]
应用程序工厂'12个月',['dateFilter',
functiondateFilter{
返回{
getMonths:函数{
var日期=新日期;
var月数=[];
对于变量i=0;i<12;i++{
months.pushdateFilterdate,“dd-MMM-yyyy”;
date.setMonthdate.getMonth-1
}
返回月份;
}
};
}
];
只需根据月份添加日期信息即可。push@OamPsy它是angularjs提供的用于格式化日期的过滤器
app.factory('twelvemonths', function() {
return {
getMonths: function() {
var date = new Date();
var months = [],
monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
days=[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];
for(var i = 0; i < 12; i++) {
months.push(days[date.getDate()]+ ' ' +monthNames[date.getMonth()] + ' ' + date.getFullYear());
}
return months;
}
};
months.push(date.getDate() + ' ' monthNames[date.getMonth()] + ' ' + date.getFullYear());