typescript 获取 日期-TypeScript 中的低格式日期/时间

2023-08-29 0 5,143 百度已收录

TypeScript 中的低格式日期/时间¶

Mat*_*son39 打字稿

我仍在尝试使用 DateTypeScript 中的对象向下转换我想要的方法。

我有一个类模块定义为:

typescript 获取 日期-TypeScript 中的低格式日期/时间

export class Module {
    constructor(public id: number, public name: string, public description: string, 
                 public lastUpdated: Date, public owner: string) { }
    getNiceLastUpdatedTime(): String {
        let options: Intl.DateTimeFormatOptions = {
            day: "numeric", month: "numeric", year: "numeric",
            hour: "2-digit", minute: "2-digit"
        };
        return this.lastUpdated.toLocaleDateString("en-GB", options) + " " + this.lastUpdated.toLocaleTimeString("en-GB", options);
    }
}

当我使用以下代码调用该方法时:

    let date = new Date(1478708162000); // 09/11/2016 16:16pm (GMT)
    let module = new Module(1, "Test", "description", date, "test owner");
    console.log(module.getNiceLastUpdatedTime());

我最终在 Control台北复制了以下内容:

'9 November 2016 16:16:02 GMT'

我想听到的是:

typescript 获取 日期-TypeScript 中的低格式日期/时间

09/11/2015 16:16

我查看了以下文档::我无法看到我做错了什么(我知道这是一个 JavaScript API 文档,但我很确定这就是 TypeScript 在幕后使用的内容)。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悟空资源网 typescript typescript 获取 日期-TypeScript 中的低格式日期/时间 https://www.wkzy.net/game/170054.html

常见问题

相关文章

官方客服团队

为您解决烦忧 - 24小时在线 专业服务