close

How do I remove time part from JavaScript date?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How do I remove time part from JavaScript date? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How do I remove time part from JavaScript date ?

  1. How do I remove time part from JavaScript date ?

    do I remove time part from JavaScript date previous answers are good. This is my method
    var todaysDate = new Date; todaysDate = todaysDate.toDateString(); console.log(todaysDate);

  2. How do I remove time part from JavaScript date ?

    do I remove time part from JavaScript date previous answers are good. This is my method
    var todaysDate = new Date; todaysDate = todaysDate.toDateString(); console.log(todaysDate);

Method 1

This is probably the easiest way:

new Date(<your-date-object>.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.

You can extend the Date object as below, so and then use the dateOnly property:

Date.prototype.getDateWithoutTime = function () {
    return new Date(this.toDateString());
}

Now <any-date-object>.getDateWithoutTime(); will output Date only

Method 2

previous answers are good. This is my method

var todaysDate = new Date; todaysDate = todaysDate.toDateString(); console.log(todaysDate);

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment