How to get year/month/day from a date object?

前端 未结 16 1044
暗喜
暗喜 2020-11-28 17:52

alert(dateObj) gives Wed Dec 30 2009 00:00:00 GMT+0800

How to get date in format 2009/12/30?

16条回答
  •  粉色の甜心
    2020-11-28 18:43

    I would suggest you to use Moment.js http://momentjs.com/

    Then you can do:

    moment(new Date()).format("YYYY/MM/DD");
    

    Note: you don't actualy need to add new Date() if you want the current TimeDate, I only added it as a reference that you can pass a date object to it. for the current TimeDate this also works:

    moment().format("YYYY/MM/DD");
    

提交回复
热议问题