Date format "dd-MM-yyyy" without pipe

1

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

this.today = Date.now();

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
source

1 answer

2

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
source