Convert javascript to date object to mysql date format (YYYY-MM-DD)

前端 未结 14 903
清歌不尽
清歌不尽 2020-12-13 18:04

I\'m trying to use javascript to convert a date object into a valid mysql date - what is the best way to do this?

14条回答
  •  执念已碎
    2020-12-13 18:26

    function js2Sql(cDate) {
        return cDate.getFullYear()
               + '-'
               + ("0" + (cDate.getMonth()+1)).slice(-2)
               + '-'
               + ("0" + cDate.getDate()).slice(-2);
    }
    

提交回复
热议问题