打字稿日期类型? [英] Typescript Date Type?

查看:49
本文介绍了打字稿日期类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在TypeScript中表达日期?日期不是 TypeScript类型,所以我使用任何对象?似乎会有一种正确的方法:

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();

尽管这是一个简单的问题,但我在Google上找不到很多。

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

推荐答案

答案非常简单,类型为 Date

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 :)

这篇关于打字稿日期类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆