javascript – How to show only date without time with Date()


I'm setting up a date to be displayed in an input, this will be today's date minus one day, but I only need the date and it's showing me Date and Time, how can I do it?

What I have so far is this:

var Hoje = new Date();
Hoje.setDate(Hoje.getDate() - 1);
var Today = Hoje.toLocaleString();
var Today = Today.replace(new RegExp("/", 'g'),"-" );


I would do like this:

 var data = new Date().toLocaleString().substr(0, 10) console.log(data)

But it's important to report that when I used this it didn't work very well in Internet Explorer (as might be expected).

In any case, I always recommend using the MomentJS library


var data = moment().format('DD/MM/YYYY');

<script src=""></script>

To decrease a day in moment , you can use add method

var date = moment().add(-1, 'days').format('DD/MM/YYYY');

<script src=""></script>
Scroll to Top