Format JavaScript date as yyyy-mm-dd

后端 未结 30 2706
再見小時候
再見小時候 2020-11-22 01:28

I have a date with the format Sun May 11,2014. How can I convert it to 2014-05-11 using JavaScript?

30条回答
  •  囚心锁ツ
    2020-11-22 02:18

    You can try this: https://www.npmjs.com/package/timesolver

    npm i timesolver
    

    Use it in your code:

    const timeSolver = require('timeSolver');
    const date = new Date();
    const dateString = timeSolver.getString(date, "YYYY-MM-DD");
    

    You can get the date string by using this method:

    getString
    

提交回复
热议问题