【问题标题】:In Javascript, how do I print out the Date object's date and time without the timezone? [duplicate]在 Javascript 中,如何在没有时区的情况下打印出 Date 对象的日期和时间? [复制]
【发布时间】:2021-01-17 21:51:35
【问题描述】:

在 Javascript 中,我如何打印出仅包含日期和时间的日期?如果我这样做,

(new Date(params['mydate'])).toString();

我明白了

Fri Jan 08 2021 10:57:20 GMT-0600 (Central Standard Time)

但如果我尝试“toDateString”,

(new Date(params['mydate'])).toDateString();

我根本没时间......

Fri Jan 08 2021

有什么方法可以在没有时区的情况下包含时间?

【问题讨论】:

  • new Date().toString().slice(0,24) 给出类似“2021 年 1 月 18 日星期一 08:29:22”的内容。

标签: javascript string date


【解决方案1】:

使用.toLocaleDateString().toLocaleTimeString()

let d = new Date();
console.log(d.toLocaleDateString() + " " + d.toLocaleTimeString());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-17
    • 2019-05-23
    相关资源
    最近更新 更多