duan0714 2018-06-12 08:25
浏览 186

日期toIsoString PHP [重复]

This question already has an answer here:

I want to have a date like new Date().toISOString() of javascript

The output is 2018-06-11T08:30:25.597Z

I tried with

(new \DateTime('now',new \DateTimeZone("UTC")))->format(\DateTime::ISO8601) // 2018-06-12T08:21:13+0000


$t = date('c', strtotime('2010-12-30 23:21:46')); //2010-12-30T23:21:46+01:00
$t2 = date(DATE_ISO8601, strtotime('2010-12-30 23:21:46')); //2010-12-30T23:21:46+01:00

$datetime = new \DateTime('2010-12-30 23:21:46');
$t3 = $datetime->format(\DateTime::ATOM); // 2010-12-30T23:21:46+01:00

I want to combine

Combined ISO 8601 date and time in UTC (YYYY-MM-DDTHH:MM:S+Timezone Offset|Z, i.e., 2018-04-18T11:02:05.261Z)

In Javascript I can have this format with

new Date().toISOString() //2018-06-12T08:24:49.321Z
</div>
  • 写回答

1条回答 默认 最新

  • douzhi3454 2018-06-12 08:33
    关注

    Your first try is almost what you need, just change \DateTime::ISO8601 to \DateTime::ATOM.

    From PHP manual:

    DateTime::ISO8601 DATE_ISO8601

    ISO-8601 (example: 2005-08-15T15:52:01+0000)

    Note: This format is not compatible with ISO-8601, but is left this way for backward compatibility reasons. Use DateTime::ATOM or DATE_ATOM for compatibility with ISO-8601 instead.

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记