since many days i'm facing a problem to convert the server UTC time zone to client's local time zone when displaying time in my ionic mobile app.
I tried the following ways
{{consts.convertToUTCDate(Message.mtmdmessages.sentDateTime) | date:'yyyy-MM-dd hh:mm Z'}}
{{consts.convertToUTCDate(Message.mtmdmessages.createDateTime) | date : 'short' : timezone}}
{{consts.convertToUTCDate(Message.mtmdmessages.createDateTime) | date:'d MMMM yyyy HH:mm:ss' : 'UTC'}}
where in consts.ts file i have the method as follows
convertToUTCDate(date) {
var dd = new Date(new Date(date).toUTCString().substr(0, 25))
console.log("the date in ist is" + new Date(date));
console.log("date in utc is " + dd);
return dd;
}
here parameter date is a number (for eg: 1509621234939 )
even i tried in this way :
var now = new Date(1509608135985);
var isoDate = new Date(now.getTime() - now.getTimezoneOffset() * 60000).toISOString();
console.log(isoDate);
isoDate = new Date(now).toISOString();
console.log(isoDate);
console.log(new Date(new Date().toUTCString().substr(0, 25)));
when i executed the above code in browser console it displays correct UTC timezone to IST , but when it is displayed in ionic App it is showing wrong time . can you suggest me what to do?