I'm running tsc inside a webpack project, with "core-js": "registry:dt/core-js#0.0.0+20160725163759"
and "node": "registry:dt/node#6.0.0+20160909174046"
Other date properties work fine:
private dateToString (date: Date) {
let month = date.getMonth();
let day = date.getDate();
let year = date.getYear() + 1900;
let dateString = `${month}/${day}/${year}`;
return dateString;
}
Typescript recognizes date.getMonth
and date.getDate
just fine, but on date.getYear
it gives
Property 'getYear' does not exist on type 'Date'.
What definition am I missing?
That API is deprecated. Try getFullYear()
instead.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getYear
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.
The getYear() method returns the year in the specified date according to local time. Because getYear() does not return full years ("year 2000 problem"), it is no longer used and has been replaced by the getFullYear() method.
Change this line from
let year = date.getYear() + 1900;
to
let year = date.getFullYear();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With