// PST
Date.prototype.toPSTString = function () {
let date = this.toString();
//date.replace.... easy part, you could use Regex to do it
return date;
};
//iso format
Date.prototype.toPSTString = function () {
function convertMinuteToMillisecond(mins) {
return mins * 60 * 1000;
}
let localDateOffsetToUtc = this.getTimezoneOffset(); //the offset between the user local timezone with UTC. In my use case of Singapore, it give me -480.
const offSetBetweenPSTAndUTC = 480;
let offsetBetweenPSTAndLocal = offSetBetweenPSTAndUTC - localDateOffsetToUtc;
let newDate = new Date(
this.getTime() + convertMinuteToMillisecond(offsetBetweenPSTAndLocal)
);
return newDate.toISOString();
};
var date = new Date(2019, 3, 5);
date.toISOString(); //"2019-04-04T16:00:00.000Z" Singapore
date.toPSTString(); //"2019-04-05T08:00:00.000Z" PST