gpt4 book ai didi

date - Typescript 认为 getYear 在 Date 类型上不存在

转载 作者:搜寻专家 更新时间:2023-10-30 20:32:57 28 4
gpt4 key购买 nike

我在 webpack 项目中运行 tsc,"core-js": "registry:dt/core-js#0.0.0+20160725163759""node": “注册表:dt/node#6.0.0+20160909174046”

其他日期属性工作正常:

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 可以很好地识别 date.getMonthdate.getDate,但是在 date.getYear 上它给出

属性“getYear”在“日期”类型上不存在。

我缺少什么定义?

最佳答案

该 API 已弃用。请尝试使用 getFullYear()

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.

关于date - Typescript 认为 getYear 在 Date 类型上不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40350288/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com