打字稿日期类型?(Typescript Date Type?)

编程入门 行业动态 更新时间:2024-10-27 02:26:22
打字稿日期类型?(Typescript Date Type?)

如何在TypeScript中表示日期? 日期不是TypeScript类型 ,所以我使用any或object ? 似乎有一个“正确”的方法可以做到:

let myDate: any = new Date();

尽管这是一个简单的问题,但我无法在Google上找到太多内容。

How do I express dates in TypeScript? Dates aren't a TypeScript type, so do I use any or object? Seems like there would be a "right" way to do:

let myDate: any = new Date();

I couldn't find much on Google, despite it being such a simple question.

最满意答案

答案非常简单,类型是Date :

const d: Date = new Date(); // but the type can also be inferred from "new Date()" already

它与其他所有对象实例相同:)

The answer is super simple, the type is Date:

const d: Date = new Date(); // but the type can also be inferred from "new Date()" already

It is the same as with every other object instance :)

更多推荐

本文发布于:2023-08-02 19:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1379964.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   类型   Typescript   Date   Type

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!