Format JavaScript Date to yyyy-mm-dd

Temperature: 0 °C

Mark ChangMark Chang

Format JavaScript Date to yyyy-mm-dd
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') ;




About the Author

Mark Chang


Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

mysql 查詢數據資料是否有重複

mysql 查詢數據資料是否有重複

pexelsphoto 有沒有試過資料庫裡上萬筆資料卻不知道是不是有重複的數據? 這時...

PHP Caching Headers

PHP Caching Headers

pexelsphotospeed 最近測試平台系統執行速度,老實說測試的有點無力~ 總...

在PHP裡添加HTTP Strict Transport Security

在PHP裡添加HTTP Strict Transport Security

要通過 PHP 啟用 HTTP 嚴格傳輸安全,請使用以下設定。 <?php //告訴瀏...

Please select an option


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