如何使用jquery ui datepicker获取当月的短名称而不是完整的月份名称?

时间:2012-03-25 16:21:34

标签: jquery jquery-ui datepicker

我的代码使用长月名而不是短名称:

var monthShortName=$.datepicker.formatDate('MM d, yy', new Date(),{ monthNamesShort: ['Jan','Feb','Mar','Apr','Maj','Jun','Jul','Aug','Sep','Okt','Nov','Dec'] });

alert(monthShortNam); // "March" and not like i want "Mar"

由于

(我使用JQuery 1.7.1 + jQuery UI 1.8.2)

编辑 - Eliasson解决方案('M'而不是'MM'):

$.datepicker.formatDate('M d, yy', new Date());

2 个答案:

答案 0 :(得分:1)

根据documentation,对于短月份名称,您在日期格式中使用M而不是MM

$.datepicker.formatDate('M d, yy', 
    new Date(),
   { monthNamesShort: ['Jan','Feb','Mar','Apr','Maj','Jun','Jul',
                      'Aug','Sep','Okt','Nov','Dec'] 
});

答案 1 :(得分:1)

var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
            var monName = monthname[currentDate.getMonth()]; 
console.log(monName);