'Date variable showing different time
I have a very simple JavaScript code:
class Person {
constructor(firstName, lastName, dateOfBirth) {
this.firstName = firstName;
this.lastName = lastName;
this.dateOfBirth = dateOfBirth;
}
}
let person1 = new Person('John', 'Doe', new Date(1993, 4, 5, 18, 30, 0));
let person2 = new Person('Hannah', 'Universe', new Date(1967, 10, 28, 2, 30, 0));
console.log(person1);
console.log(person2);
The output of this is:
Person {
firstName: 'John',
lastName: 'Doe',
dateOfBirth: 1993-05-05T16:30:00.000Z
}
Person {
firstName: 'Hana',
lastName: 'Universe',
dateOfBirth: 1967-11-28T01:30:00.000Z
}
How can the person1 time be 16:30 if I specified 18:30 in the constructor, and a the same time person2 has 01:30 and I specified 02:30 in the constructor? The person1 difference between input and output is 2 hours, person2 difference between input and output is 1 hour. How is that possible?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
