How do I get the day of the month in javascript?

后端 未结 4 1041
醉话见心
醉话见心 2020-12-15 02:25

I need to get the day of the month from a Date object but it seems that the getDay() method returns the day of the week. Is there a function that returns the da

相关标签:
4条回答
  • 2020-12-15 02:51

    Use date_object.getDate() to get the month day.

    From the MDN docs link:

    "Returns the day of the month for the specified date according to local time."

    0 讨论(0)
  • 2020-12-15 02:55
    var date = new Date().getDate();
    
    0 讨论(0)
  • 2020-12-15 03:07

    Try getDate() instead. Confusing naming, but that's life...

    0 讨论(0)
  • 2020-12-15 03:15
    const date = new Date();
    
    const day = date.getDate();
    const month = date.getMonth() + 1;
    const year = date.getFullYear();
    
    0 讨论(0)
提交回复
热议问题