gpt4 book ai didi

javascript - Moment.js 不喜欢我的时间格式

转载 作者:行者123 更新时间:2023-11-30 15:27:39 25 4
gpt4 key购买 nike

我从 JSON 返回一个 SQL 日期,它看起来像这样:ts '2017-03-11 00:00:00'

当我尝试应用 moment.js 格式时,我收到此错误:

Deprecation warning: value provided is not in a recognized ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non ISO date formats are discouraged and will be removed in an upcoming major release.

我该如何解决这个问题?

这是我的代码:

<script>
function PopulateReviewTimeStamps() {
// Populate timestamp data div
console.log("Review timestamp CFC called");
$.ajax({
url: 'cfcs/reviewdata.cfc?method=getTimeStampData&returnformat=json',
data: {
ticket_id: $("##ticket_id").attr("Value")
},
success: function(response) {
console.log("success function called");
var value = response;
var datetime = moment(value);
var date = datetime.format('MMMM Do, YYYY');
var time = datetime.format('h:mma');


// append new option to list
console.log("about to change div" + value);
$('##sentDate').html(date + " at " + time);


// PopulateOdometers();
},
error: function(msg) {
console.log("Something went wrong with populating stats function");
}
})
}
</script>

更新:我从 AJAX 请求更改为返回类型“日期”。我不再收到无效日期,但我的日期显示为:2000 年 11 月 5 日凌晨 12:00。

控制台日志如下:原始日期值:March, 11 2017 00:00:00 -0500 <----- moments.js 运行前

即将将 div 更改为:November 5th, 200012:00am <----- 这是在运行 moments.js 之后

最佳答案

这个:-

var datetime = moment(value);

需要:-

var datetime = moment(value,'MM-DD-YYYY h:m'); // pass desired date-time format

引用:- https://momentjs.com/docs/#/parsing/string-format/ (来自 Pointy)

关于javascript - Moment.js 不喜欢我的时间格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42737962/

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