2013-10-28 48 views
-4

我想從這樣的「28/10/2013 12:00:00 AM」 這樣的長日期時間轉換爲像這樣的「28/10/2013」​​這樣的短日期格式Java腳本,但我不知道如何..使用javascript從日期時間轉換爲短日期格式

我嘗試了以下功能,但它並沒有正常工作

function dateToShort(myDate) { 

       var convertedStartDate = new Date(myDate); 
       var month = convertedStartDate.getMonth(); 
       var day = convertedStartDate.getDay(); 
       var year = convertedStartDate.getFullYear(); 
       var shortStartDate = day+ "/" + month+ "/" + year; 
       return shortStartDate; 
      } 

當我用這個參數「稱之爲」 28/10/2013" 它返回「5/4/2015」!!!

Regards

+0

http://meta.stackexchange.com/questions/156810/stack-overflow-問題清單 – CodingGorilla

+0

所有你需要的,你會在MDN上找到Date(日期)(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)。 – Sirko

+1

http://momentjs.com,不客氣 – naivists

回答

-1

我解決了使用簡單的函數

function dateToShort(myDate) { 

       return myDate.substr(0, 10); 
      } 

謝謝 「Rhyono」

關於問題..

相關問題