Invalid Date Error in ionic 3 in IOS only. (Working fine in Android).
var f = data.posted_date +' '+ data.posted_time;
var d = new Date(); // working Fine
var b = new Date(f); // b becomes invalid Date
its working fine in android but not working in IOS.
Complete Function:
getProperTime() {
this.dailyDiary.forEach(element => {
var d = new Date(element.posted_date + " " + element.posted_time);
var hours: any = d.getHours();
var minutes: any = d.getMinutes();
var ampm = hours >= 12 ? "pm" : "am";
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? "0" + minutes : minutes;
var strTime = hours + ":" + minutes + " " + ampm;
console.log("this is the getProperTime function output: " + strTime);
element.posted_time = strTime;
});
}
This function shows as result:
12:NaN am