Date format "dd-MM-yyyy" without pipe


I have this doubt, I need to record it in a variable with that format, but the pipe seems to work only in HTML.

I need today's date with the format dd-MM-yyyy

Today's date is like this =;

But there I stay ... I've been looking but I can not find it, only forms come out using the pipe.

Greetings and thanks

asked by tremenk 21.03.2018 в 18:04

1 answer


you just have to handle the date in the following way:

let mi_fecha = new Date()
console.log('${mi_fecha.getDate()}-${mi_fecha.getMonth() + 1}-${mi_fecha.getFullYear()}' )

The only care is that the month always starts at 0 which is January

answered by 21.03.2018 / 18:20