开发者

Get month name instead of number

开发者 https://www.devze.com 2023-04-06 03:59 出处:网络
I am using the jQuer开发者_JS百科y datepicker plugin. I can get the month number by $(\"#datepicker\").datepicker(\'getDate\').getMonth()+1

I am using the jQuer开发者_JS百科y datepicker plugin. I can get the month number by

$("#datepicker").datepicker('getDate').getMonth()+1

How can I get the month name directly (i.e. without using a switch case)?


If you want a simple solution this is it:

var months = [ "January", "February", "March", "April", "May", "June", 
               "July", "August", "September", "October", "November", "December" ];

var selectedMonthName = months[$("#datepicker").datepicker('getDate').getMonth()];

A more complicated but more customizable way would be to use a formatter (my comment). Then see this question and answer.


Edit: I guess getMonthName doesn't work?

Well really the 'right' way to do this is to use formatDate: http://docs.jquery.com/UI/Datepicker/formatDate

var monthName = $.datepicker.formatDate('MM', $("#datepicker").datepicker('getDate'));


This is a very old thread but hey, improvements are always welcome (I hope!)

This works well if you have optional languages set.

$( "#datepicker" ).datepicker( "option", "monthNames")[$("#datepicker").datepicker('getDate').getMonth()]
0

精彩评论

暂无评论...
验证码 换一张
取 消