【问题标题】:JSON response date doesnt matchJSON 响应日期不匹配
【发布时间】:2017-06-28 15:35:32
【问题描述】:

谁能解释一下这个问题,我正在使用下面的代码,它从 ajax 请求输出 JSON 响应

    console.log('get_therapist_sessions, response);
    response.forEach(function(index){
      console.log(index);
    });

但是,当我 console.log 日期正确,但检查实际对象日期不正确时,我想要的是能够使用我使用 console.log 时出现的日期

【问题讨论】:

  • 您是否在某处使用 .ToJSON 来转换您的日期对象。可能是时区偏移差异。

标签: jquery json ajax wordpress


【解决方案1】:

这是因为你的对象 start_dateend_date 是 Date 对象,一开始不是字符串。

如果您想从日期转换为字符串,请尝试start_date.toString()end_date.toString()。这就是console.log() 没有告诉你的。

【讨论】:

  • 恐怕没什么区别,也试过用String(index.start_date)
  • 没有区别是什么意思?你有错误吗? typeof(index.start_date) 的输出是什么?
  • 更新代码response.forEach(function(index){ console.log(index); console.log(typeof(index.start_date)); });说是字符串
  • 我认为您必须分享更多代码,因为仅此而已我无法为您提供更多帮助:/
猜你喜欢
  • 1970-01-01
  • 2016-01-07
  • 1970-01-01
  • 2015-05-18
  • 1970-01-01
  • 2016-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多