gpt4 book ai didi

javascript - 从 JavaScript 中的日期中删除 GMT-#### 文本?

转载 作者:行者123 更新时间:2023-12-02 22:05:19 26 4
gpt4 key购买 nike

我想从结果中删除“GMT-####”文本。日期/时间结果将根据用户输入的搜索条件而有所不同。

    for (var j = 0; j < resultCountGLM; j++) {

var featureAttributes2 = results[1].features[j].attributes;
//console.log(featureAttributes2)

if (attr = "DATE_UTC") {
attr1 = "Detected during the 1-hour period beginning"
var dateGM = new Date(featureAttributes2[attr]);
resultItems.push("<p class='reportTextResults_font'><b>" + attr1 + ":</b> " + dateGM + "</p>");
}
}
resultItems.push("<br>");

示例输出:

    Detected during the 1-hour period beginning: Thu Jan 02 2020 14:00:00 GMT-0600 (Central Standard Time)
Detected during the 1-hour period beginning: Thu Jan 02 2020 16:00:00 GMT-0600 (Central Standard Time)

期望的输出:

    Detected during the 1-hour period beginning: Thu Jan 02 2020 14:00:00 (Central Standard Time)
Detected during the 1-hour period beginning: Thu Jan 02 2020 16:00:00 (Central Standard Time)

最佳答案

如果你想使用普通的 javascript,你有两个选择。要么自己删除它,要么查看 .toXXX 函数之一。示例:

new Date().toLocaleString()
//"1/14/2020, 1:05:58 PM"

如果您需要它完全如此或可能更精细,有很多库可以帮助格式化日期。

关于javascript - 从 JavaScript 中的日期中删除 GMT-#### 文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59739376/

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