How do I remove time part from JavaScript date?

后端 未结 3 1113
夕颜
夕颜 2020-12-17 07:52

I have a date \'12/12/1955 12:00:00 AM\' stored in a hidden column. I want to display the date without the time. How do I do this?

3条回答
  •  悲哀的现实
    2020-12-17 08:14

    Parse that string into a Date object:

    var myDate = new Date('10/11/1955 10:40:50 AM');
    

    Then use the usual methods to get the date's day of month (getDate) / month (getMonth) / year (getFullYear).

    var noTime = new Date(myDate.getFullYear(), myDate.getMonth(), myDate.getDate());
    

提交回复
热议问题