我有一個以字符串形式提供的日期,例如09/12/2012。將JavaScript字符串轉換爲整數
如果字符串是今天,我希望顯示「今日」,否則我希望顯示09/12/2012。
用我的方法如下所示的問題是,像09月被解析爲0,而不是9
什麼是做到這一點的最好方法是什麼?謝謝
var currentDate = new Date();
dateText='09/12/2012';
var a=dateText.split('/');// mdY
$("#date").text(((parseInt(a[0])-1==currentDate.getMonth()&&parseInt(a[1])==currentDate.getDate()&&parseInt(a[2])==currentDate.getFullYear())?'Today':dateText));
你會發現[這裏](http://stackoverflow.com/questions/7142123/converting-an-array-of-string-into-integer-using- jquery)如何使用JavaScript和jQuery將字符串轉換爲Int – VBH