将任何日期字符串转换为没有时区的时间戳 [英] convert any date string to timestamp without timezone

查看:639
本文介绍了将任何日期字符串转换为没有时区的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在获取xml和rss feed并将数据放入数据库。到目前为止,我已经遇到两种不同的日期格式...

  Wed,21 Jul 2010 00:28:50 GMT 

  2010-07-20T17:33:19Z 

我相信会有更多的。我的postgresql数据库的日期是没有时区的时间戳。在php中是否存在现有的函数,还是有一个将任何日期字符串转换为没有时区(Ymd H:i:s)的时间戳的过程?

解决方案

使用 date strtotime

  $ date = date 'Ymd H:i:s',strtotime('Wed,21 Jul 2010 00:28:50 GMT')); 
回音$ date;

结果:

 code> 2010-07-21 05:28:50 

  $ date = date('Ymd H:i:s',strtotime('2010-07-20T17:33:19Z')) 
echo $ date;

结果:

 code> 2010-07-20 22:33:19 


I'm getting xml and rss feeds and putting the data into a database. I've run into two different date formats so far...

Wed, 21 Jul 2010 00:28:50 GMT

And

2010-07-20T17:33:19Z

I'm sure there will be more. My postgresql database for the date is timestamp without time zone. Is there an existing function in php or is there a procedure to convert the any date strings to timestamp without time zone (Y-m-d H:i:s)?

解决方案

Use date with strtotime:

$date = date('Y-m-d H:i:s', strtotime('Wed, 21 Jul 2010 00:28:50 GMT'));
echo $date;

Result:

2010-07-21 05:28:50

.

$date = date('Y-m-d H:i:s', strtotime('2010-07-20T17:33:19Z'));
echo $date;

Result:

2010-07-20 22:33:19

这篇关于将任何日期字符串转换为没有时区的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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