How to format datetime in angular using typescript?

Asked

Viewed 227 times

0

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

I tried with javascript but could not. How do using angular?

1 answer

0


I got.

   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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.