我从SQL Server获取一个日期,然后通过ASP.NET。我正在迭代jQuery中的对象列表,并希望显示一些日期以及其他数据。但是,无论什么时候来自数据库(从早些时候开始的各种日期/时间),分钟总是读取10.发生了什么?
这是一些Web浏览器控制台输出。这些都是在一小时后的不同时间进入的,但他们都说过了10点。
this.CreatedTime = /Date(1507924194433)/
moment-formatted = 10/13/17 12:10pm
this.CreatedTime = /Date(1507924096347)/
moment-formatted = 10/13/17 12:10pm
this.CreatedTime = /Date(1507923917443)/
moment-formatted = 10/13/17 12:10pm
this.CreatedTime = /Date(1507923693083)/
moment-formatted = 10/13/17 12:10pm
this.CreatedTime = /Date(1507667688047)/
moment-formatted = 10/10/17 1:10pm
this.CreatedTime = /Date(1507667348210)/
moment-formatted = 10/10/17 1:10pm
以下是代码:
$.each(data, function () {
console.log("this.CreatedTime = " + this.CreatedTime);
console.log("moment-formatted = " + moment(this.CreatedTime).format("MM/DD/YY h:MMa"));
});
以下是SQL Server的实际日期:
2017-10-13 12:49:54.433
2017-10-13 12:48:16.347
2017-10-13 12:45:17.443
2017-10-13 12:41:33.083
2017-10-10 13:54:04.227
2017-10-10 13:34:48.047
答案 0 :(得分:3)
尝试将格式更改为
MM/DD/YY h:mma
^^
MM
是几个月,mm
是几分钟。
答案 1 :(得分:2)
我认为返回的10
是月份。在MM
时刻是月。您想使用mm
。
答案 2 :(得分:1)
您的日期格式不正确,请尝试moment(this.CreatedTime).format("MM/DD/YY h:mma")