douhaodang0403 2017-04-22 07:47
浏览 58

如何在PHP CodeIgniter中将字符串格式的日期时间转换为正确的日期和时间格式?

I got a JSON response of date and time in string format, and I want it to convert into proper date and time. I'm using a API to get a response and that comes in JSON code, but while it is in string form. How can I convert it into Proper Date and Time.

I got following response:

"start_time": 1492841592,
"end_time": 1492841619,
"seconds": 22392,
"duration": "00:00:27",
"_drm": 0.45,

And I want output in :

01:10pm 16 Mar

This format.

To convert it I'm trying to use date() function from PHP. But it wont give me proper result. I'm referred following question:

How to convert string to date format in PHP?

how to convert string day into date time format in php

how to convert String time to dateTime format in php?

  • 写回答

1条回答 默认 最新

  • dou4381 2017-04-23 20:23
    关注

    Are you looking for something like this?

    $json = <<<'JSON'
    {
      "start_time": 1492841592,
      "end_time": 1492841619,
      "seconds": 22392,
      "duration": "00:00:27",
      "_drm": 0.45
    }
    JSON;
    
    $dt = json_decode($json);
    
    echo date('h:ia M j', $dt->start_time);
    

    Output:

    06:13am Apr 22
    

    Demo

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算