如何将字符串转换为日期 [英] How to convert string to date

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

问题描述

我将以不同的格式转换像2011年7月22日下午7:42的字符串。
我尝试使用strtotime和date_parse_from_format函数,但是在这种情况下它们不能正常工作。我想这个问题的原因可能是子串in。

I would convert a string like that "July 22, 2011 in 7:42pm" in a different format. I tried to use both strtotime and date_parse_from_format functions but they don't correctly work in this case. I suppose that the reason of this problem could be the substring "in".

如何在Date类型或时间戳中转换该格式?

How can I convert that format in a Date type or in a timestamp?

推荐答案


我想这个问题的原因可能是子串in。

I suppose that the reason of this problem could be the substring "in".

据我所见,你是对的。至少 i 是一个标识符(Minutes with leading zero)本身,所以你必须逃脱它。

As far as I can see you are right. At least the i is an identifier ("Minutes with leading zeros") itself, thus you must escape it.

var_dump(date_parse_from_format('F d, Y \i\n g:ia', $string));

请参阅 date()示例#2

See date() Example #2

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

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