2012-06-28 35 views
1

我正在尋找正確的通配符與jquery.datepicker.parseDate()在使用doc 它說使用'...'的文字文本和「別的 - 文字文本」。問題出現在當天數字後面的'th','rd','nd'或'st'時。jQuery的日期選擇器解析日期通配符

我已經試過

$.datepicker.parseDate('M d... 2012', 'Jun 28th, 2012'); 

,並沒有奏效。有什麼建議麼?

+0

與PHP的日期功能序後綴字符是「S」 –

回答

1

目前,您無法使用parseDate執行此操作,請參見Adding "st, nd, rd, th" to jquery datepicker以及以下拉取請求以添加此功能 - https://github.com/jquery/jquery-ui/pull/438

我會建議在撥打parseDate前一天結束時刪除'st','rd','nd'和'th',然後使用它。

$.datepicker.parseDate('M dd yy', 'Jun 28th 2012'); 

雖然不理想,但也可以。

var myDate; 

try { 
    myDate = $.datepicker.parseDate('M ddth yy', 'Jun 28th 2012'); 
} catch (e) {} 
try { 
    myDate = $.datepicker.parseDate('M ddst yy', 'Jun 28th 2012'); 
} catch (e) {} 
try { 
    myDate = $.datepicker.parseDate('M ddrd yy', 'Jun 28th 2012'); 
} catch (e) {} 
try { 
    myDate = $.datepicker.parseDate('M ddnd yy', 'Jun 28th 2012'); 
} catch (e) {} 
+0

什麼是解析「M DDST YY」(第二次嘗試),而「M ddth YY」(第一次)已經是正確的呢? –