I want to convert year string into a date type like in the following example:
var date = new Date('1999');
console.log(date); // result -> Thu Dec 31 1998 16:00:00 GMT-0800 (Pacific Standard Time)
The problem is with time zone. Because the string is not properly formated and it is treated as UTC time zone.
How to convert year string properly and treat as local time?
I know that it will work if I append day and month like this '01/01/' + '1999' but is it possible some other solution?
new Date(1999, 0)should do. Pass it as year+month parameters, not a string to be parsed.