Get month name instead of number

戏子无情 提交于 2019-12-05 18:42:50
dacwe

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()]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!