Ionic 2 - Convert Json date to string


#1

How to convert JSON date from REST

/Date(1480525200000+0700)/

to string format dd/MM/yyyy


#2

I would highly recommend using moment.js for all your date handling.


#3

Create a new date from the milliseconds

let today = new Date(1480525200000);   

let dd = today.getDate();
let mm = today.getMonth()+1; //January is 0!
let yyyy = today.getFullYear();

let sdd; let smm; let stoday;
if(10>dd) {sdd='0'+dd;} else{sdd=dd;} 
if(10>mm) {smm='0'+mm;} else{smm=mm;} 

stoday =  sdd + '/' + smm + '/' + yyyy ;

good luck