格式化日期字符串 - PHP [英] Formatting a date string - PHP

查看:128
本文介绍了格式化日期字符串 - PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态分配的日期从搜索引擎api结果集输入到一个多维数组, $ search_results ['Date']

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

有三种结果测试有两种类型的Date Data返回,第一个引擎返回:

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


  1. 示例1: 2013-07-22T12:00:03Z

  2. 示例2: 2013-07-23T18:18: 15Z

  3. 示例3: 2013-07-21T23:57:04Z

  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. 示例1 : 1374495037

  2. 示例2: 1374528579

  3. 示例3: 1374515617

  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?

我希望返回的格式为:

2013年7月22日。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?

感谢贵司。

推荐答案

对于第一个例子,可以使用第一个strtotime(),一个将datetime转换为UNIX时间戳的函数,如下所示: p>

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

第二个例子你已经有字符串作为UNIX时间戳,所以你不需要strtotime()

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);

为日期格式的其他选项咨询: http://php.net/manual/en/function.date.php

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

这篇关于格式化日期字符串 - PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆