How to format angular datetime using typeScript?

0

I want to get current date and time in '2018-05-25 20:01:01' format.

I tried with javascript but I could not. How do you use angled?

    
asked by anonymous 26.05.2018 / 01:01

1 answer

0

I did it.

   var d = new Date();
    var strData =
        d.getFullYear() + "-" +
        ("00" + (d.getMonth() + 1)).slice(-2) + "-" +
        ("00" + d.getDate()).slice(-2) + " " +          
        ("00" + d.getHours()).slice(-2) + ":" +
        ("00" + d.getMinutes()).slice(-2) + ":" +
        ("00" + d.getSeconds()).slice(-2);
    
26.05.2018 / 02:39