问题
I need to parse dates like '070126' to '26 Jan 2007'. I thought I could use the datepicker, but it gives me the an error...
$.datepicker.parseDate('ymmdd', '070126') #=> Missing number at position 6
I am starting to think that this could be a bug...
$.datepicker.parseDate('y-mm-dd', '07-01-26') #=> Fri Jan 26 2007 00:00:00 GMT+0100 (CET)
Any advice?
Thanks..
回答1:
Are you sure it is not working? I have no problems with your code: http://jsfiddle.net/ND2Qg/
回答2:
Finally i just preprocessed the date. The function add_scores() just adds '-' after each two characters.
$.datepicker.parseDate('ymmdd', add_scores('070126'));
add_scores('070126'); //=> '07-01-26'
function normalize_date(date){
var normalized_date = [];
$.each("ymd", function(index, format_option){
normalized_date.push(date[index*2] + date[(index*2)+1]);
});
return normalized_date.toString().replace(/,/g, '-');
}
来源:https://stackoverflow.com/questions/5390521/jquery-ui-datepicker-parsedate-missing-number-at-position-6