Javascript Date Parse String to Date with timezone

Description

Javascript Date Parse String to Date with timezone


// If we were in pacific time (GMT-0800) this would return 1036051200000
// but would return other values in different time zones. This is because
// it does not specify a time zone in the string
console.log( Date.parse("Oct 31, 2020") );

// Returns 1028851200000 irrespective of the user's time zone
console.log( Date.parse("Fri, 09 Aug 2020 00:00:00 GMT") );

// Returns 1028876400000 in time zone GMT-0800 but different in others
console.log( Date.parse("Fri, 09 Aug 2020 00:00:00") );

// Returns 0 irrespective of the time zone
console.log( Date.parse("Thu, 01 Jan 1970 00:00:00 GMT") );

// Returns 28800000 irrespective of the time zone
console.log( Date.parse("Thu, 01 Jan 1970 00:00:00 GMT-0800") );



PreviousNext

Related