4

我需要将“070126”之类的日期解析为“2007 年 1 月 26 日”。我以为我可以使用日期选择器,但它给了我一个错误......

$.datepicker.parseDate('ymmdd', '070126') #=> Missing number at position 6

我开始认为这可能是一个错误......

$.datepicker.parseDate('y-mm-dd', '07-01-26') #=> Fri Jan 26 2007 00:00:00 GMT+0100 (CET)

有什么建议吗?

谢谢..

4

2 回答 2

1

你确定它不工作吗?我的代码没有问题:http: //jsfiddle.net/ND2Qg/

于 2011-03-22T12:13:46.197 回答
1

最后我只是预处理了日期。函数 add_scores() 只是在每两个字符后添加“-”。

$.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, '-');
    }
于 2011-03-22T13:11:38.833 回答