Problems with jQuery DatePicker setting a second DatePicker
So, I've managed to code this so far. Whats meant to happen is a user selects the 'arrdate
', then t开发者_如何学Gohe code automatically sets the endDate of the 'depdate
' to 1 day later. However, the issue here is that the 'arrdate'
format is non-US
, ie; dd/mm/yy
, yet the code that is meant to push it one day later is picking it up as mm/dd/yy.
This pushes everything out of whack, eg, selecting today 11/08/2011
in the arrdate sets the depdate to 09/11/2011.
I've tried several ways to no avail - anyone that can tell me where I can set the format better? Thanks!
$(function() {
$( "#arrdate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy',
minDate: 0 ,
onSelect: function(date){
var selectedDate = new Date(date);
var msecsInADay = 86400000;
var endDate = new Date(selectedDate.getTime() + msecsInADay);
$("#depdate").datepicker( "option", "minDate", endDate );
}
});
$( "#depdate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy'
});
});
I had the same problem yesterday. So I had to make a bit of a workaround, before you start adjusting the date +1day, switch it around:
//Convert Date from dd/mm/yy to mm/dd/yy
var iDay = date.substring(0,2);
var iMth = date.substring(3,5);
var iYr = date.substring(8,11);
var date = iMth+"/"+iDay+"/"+iYr;
var selectedDate = new Date(date);
You may have to do something similar to convert it back to dd/mm/yy
精彩评论