【问题标题】:JSON Datetime php objectJSON 日期时间 php 对象
【发布时间】:2014-08-06 14:07:02
【问题描述】:

我向 JS 发送一个 json datetime 对象,我如何将它转换为 datetime JS 对象?

PHP 返回:

"date": {
  "lastErrors": {
     "warning_count":0,
     "warnings":[],
     "error_count":0,
     "errors":[]
  },
  "timezone": {
    "name":"Europe\/Warsaw",
    "location": {
      "country_code":"PL",
      "latitude":52.25,
      "longitude":21,
      "comments":""
    }
  },
  "offset":7200,
  "timestamp":1399413600
}

我需要用 JavaScript 小时和分钟来轻松总结和显示。

【问题讨论】:

标签: javascript php json


【解决方案1】:

使用 unix 时间戳从 JSON 到 Datetime 对象

s = '{"date":{"lastErrors":{"warning_count":0,"warnings":[],"error_count":0,"errors":[]},"timezone":{"name":"Europe\/Warsaw","location":{"country_code":"PL","latitude":52.25,"longitude":21,"comments":""}},"offset":7200,"timestamp":1399413600}}'
new Date(JSON.parse(s).date.timestamp * 1000)

【讨论】:

    猜你喜欢
    • 2011-03-21
    • 2020-01-07
    • 1970-01-01
    • 1970-01-01
    • 2020-07-15
    • 1970-01-01
    • 2014-05-26
    • 2017-04-25
    • 1970-01-01
    相关资源
    最近更新 更多