【问题标题】:convert json callback data to date将 json 回调数据转换为日期
【发布时间】:2015-04-09 12:35:53
【问题描述】:

我可以帮助我将此字符串转换为日期格式吗?

这是 JSon 的名称和值

notBefore: 1413936000000
notAfter: 1479427199000

我认为这需要转换为美国格式日期 mm/dd/yyyy

回调字符串如下所示:

response.endpoints[0].details.cert.notBefore
response.endpoints[0].details.cert.notAfter

【问题讨论】:

标签: javascript jquery json date


【解决方案1】:

继续制作一个新的Date

new Date(notBefore)

如果你的值确实是字符串,你可以parseInt()他们

JSFiddle Example

如果您需要 mm/dd/yyyy 格式的简单示例,这里有一个可以帮助您启动和运行的工作小提琴。

var notBefore = 1413936000000;
var date = new Date(notBefore);
var formattedDate = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();

With Basic Format JSFiddle

【讨论】:

  • 该值在 json 数据中,所以我必须引用它,但我得到 Nan/Nan/Nan var notbefore = response.endpoints[0].details.cert.notBefore var date = new Date(notBefore ) var formattedDate = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear()
  • typeof 字符串吗?正如我在答案中指出的那样,您可能需要先parseInt()
  • 根据您的建议,它的工作方式如下: var date = new Date(parseInt(response.endpoints[0].details.cert.notBefore))
猜你喜欢
  • 1970-01-01
  • 2015-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多