Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

angular set timezone

// 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
Comment

PREVIOUS NEXT
Code Example
Javascript :: setting up react on visual studio code 
Javascript :: get element by id angular 
Javascript :: Material-ui account circle icon 
Javascript :: how to get nested array using lodash 
Javascript :: swagger ui express 
Javascript :: javascript.loop 
Javascript :: how to read excel file in nodejs 
Javascript :: how to unfreeze object in javascript 
Javascript :: Difference Between for...of and for...in Statement 
Javascript :: js get array object from local storage 
Javascript :: react native fast image webp ios 
Javascript :: js find 
Javascript :: js module pattern 
Javascript :: ajax form submit 
Javascript :: show password using javascript 
Javascript :: how to display message in javascript 
Javascript :: code cat 
Javascript :: js role giver 
Javascript :: add numbers from array nodejs 
Javascript :: array function in javascript 
Javascript :: fastify query 
Javascript :: check if string javascript 
Javascript :: find element vs find elements in selenium 
Javascript :: LEAODE MAJE 
Javascript :: difference between w component did update and did mount 
Javascript :: Material-ui account box icon 
Javascript :: does javascript buelt applications 
Python :: months list python 
Python :: uuid regex 
Python :: how to iterate through files in a folder python 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =