dpdbu24262 2013-07-23 20:42
浏览 19
已采纳

格式化日期字符串 - PHP [重复]

This question already has an answer here:

I have a dynamically allocated date from a search engine api results set entered into a multidimensional array, $search_results['Date']

There are two types of Date Data returned, first engine returns, for three result tests:

  1. Example 1: 2013-07-22T12:00:03Z
  2. Example 2: 2013-07-23T18:18:15Z
  3. Example 3: 2013-07-21T23:57:04Z

And for the same items, different engine:

  1. Example 1: 1374495037
  2. Example 2: 1374528579
  3. Example 3: 1374515617

I was hoping somebody here may have had experience on formatting dates and may be able to help me out?

I would like the format returned to be:

22nd July, 2013. 12.00pm

However the time part is not strictly necessary, but it would be nice to have the date sorted properly.

It seems the second engine returns the date in a bizarre format, can anybody figure it out? I am from Europe, we do dates different to those of you in America!?

Does anybody have any suggestions on how to format these dates?

Thanks Guys.

</div>
  • 写回答

1条回答 默认 最新

  • duanhao4156 2013-07-23 20:53
    关注

    for first example, you can use first strtotime(), a function that converts datetime to UNIX timestamp like this:

    $date = date('d/m/Y H:i:s',strtotime('2013-07-23T18:18:15Z'));
    echo $date.'<br/>'; //put here just for  testing
    

    and for second example you already have string as UNIX timestamp, so you don't need strtotime()

    $date = date('d/m/Y H:i:s','1374495037');
    echo $date.'<br/>';//put here just  for testing
    

    format that you would like to return would be:

    date('jS F, Y. h.ia',$unix_timestamp);
    

    for other options for date formats consult: http://php.net/manual/en/function.date.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题