0

Important notes:

  1. The machine's date & time setting is the automatic setting
  2. The machine is located in Malaysia, and the timezone is GMT +8
  3. Malaysia do not have daylight saving

Question:

When using the Date constructor with the number value which representing the number of milliseconds since January 1, 1970, 00:00:00 UTC. These two numbers (378000000000, 379000000000) are giving different timezone.

output example

This was tested in both Chrome devtool console and node.js, they're giving the same result. Came across this post but it doesn't seems relevant.

Any clue / explanation please?

Below is the quick snippet and the screenshot of result enter image description here

console.log(new Date(378000000000).toString());
console.log(new Date(378000000000).toLocaleString());
console.log('-----------');
console.log(new Date(379000000000).toString());
console.log(new Date(379000000000).toLocaleString());
Garbee
  • 10,581
  • 5
  • 38
  • 41
ChinKang
  • 4,212
  • 2
  • 17
  • 29

2 Answers2

0

You have to use the getTimezoneOffset() method. For example:

const melissaBirthdayParty = new Date();
let birthdayPartyTime = melissaBirthdayParty.getTimezoneOffset();
console.log("The party is at " + birthdayPartyTime)
0

Thanks to Jaromanda X! Learnt new history of my own country. Refer to https://en.wikipedia.org/wiki/Time_in_Malaysia

enter image description here

ChinKang
  • 4,212
  • 2
  • 17
  • 29