How do I remove time part from JavaScript date?

后端 未结 3 1109
夕颜
夕颜 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:22

    This is probably the easiest way:

    new Date(.toDateString());
    

    Example: To get the Current Date without time component:

    new Date(new Date().toDateString());
    

    gives: Thu Jul 11 2019 00:00:00 GMT-0400 (Eastern Daylight Time)

    Note this works universally, because toDateString() produces date string with your browser's localization (without the time component), and the new Date() uses the same localization to parse that date string.

提交回复
热议问题