IOnic 2 Rc1: How to convert date into this 'yyyy-MM-dd' format in angular 2


i want to convert current data into ‘yyyy-MM-dd’ format in .ts file. i template it can easily be done by using data pipe. how to do that in typescript.

In template:

{{date | date:‘yyyy-MM-dd’}}

How to convert in this format ‘yyyy-MM-dd’ in typescript.

now i am just getting current date by using this. = new Date(); but need to convert it into given format. Please guide how to do that… Thanks!


You can use some good old javascript to handle the data, seems like the pipe is pretty unstable. What I did was just:

        //Gets it as YYYY-MM-DD
        var dateData = this.s.depatureDate.split('-');
        var year = dateData [0];
        var month = dateData [1];
        var day = dateData [2];
        var dateFormated = day + "/" + month + "/" + year;


I strongly suggest using moment for all date and time handling.


What i did was. Date();

this.today_date =’-’+(’-’;