Loading...

Format JavaScript Date to yyyy-mm-dd

Temperature: 0 °C

Mark ChangMark Chang


JavaScript將Sun May 01,2018轉換成yyyy-mm-dd
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();

if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;

return [year, month, day].join('-');
}
document.getElementById('res').innerHTML = formatDate('Sun May 01,2018') ;

以上紀錄~
https://innstory.com/story-Format_JavaScript_Date_to_yyyymmdd-1530

Prev
 Welcome

Next
解決iphone_不能使用colorbox_滑動的方式 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

要如何知道ajax執行失敗原因?

要如何知道ajax執行失敗原因?

只要在error的function 更改為以下寫法即可: error:...

Ubuntu環境下apache 目錄啟動.htaccess 功能

Ubuntu環境下apache 目錄啟動.htaccess 功能

.htaccess 檔案是目錄層面的設定檔,可以對目錄變更 Apache 的設定。 要...

javascript change css class

javascript change css class

javascript 使用classList是一個方便的替代方法,可以將元素的類列表作...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format