Get today's date from jquery datepicker

陌路散爱 提交于 2019-12-01 06:09:35

问题


I need to change the default display of currentText property in jquery datepicker from "Today" to "Today: Septmeber 14, 2012". So the question is does the datepicker expose today's date via some method? or do I have to create my own JS new Date() and get the date from there, which I am trying to avoid!

$('#txtSelectedDate').datepicker({
        showButtonPanel: true,
        currentText: "Today: " + getTodaysDate(); // Is there such a method?
    });

回答1:


Yes, the currentText is what you are looking for.

$('#txtSelectedDate').datepicker({
    showButtonPanel: true,
    currentText: "Today:" + $.datepicker.formatDate('MM dd, yy', new Date())  
});​

DEMO




回答2:


If you need to initialize the datepicker with current date, you could use:

$(".selector").datepicker( "option", "gotoCurrent", true );

And of course you have the dateFormat which take a format defined here




回答3:


If you need to initialize the datepicker with current date, you could use:

 $(".selector").datepicker( "option", "gotoCurrent", true );


来源:https://stackoverflow.com/questions/12428203/get-todays-date-from-jquery-datepicker

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