如何让约会时间变成这样?
您好,我正在保存来自 rss feed url 的数据。从那以后我就得到了这样的约会时间。
2011 年 1 月 2 日星期日 03:04:02 GMT+5:30
如何使用 php 将此日期更改为 2011 年 1 月 2 日下午 03:04 这种格式? 任何人都知道解决方案请帮助我。
Hi I am saving data from rss feed url. From that me got date time like this.
Sun, 2 January 2011 03:04:02 GMT+5:30
How to change this date to this format 2nd January 2011, 03:04 PM using php?
any body knows the solution please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 strtotime 函数来转换现有字符串和 'r ' 说明符到 date 函数,如下所示(看起来您希望它在RFC 2822 格式,如果没有相应调整):
顺便说一句,请确保您通过 date_default_timezone_set 等
You can se the strtotime function to convert the existing string and the 'r' specifier to the date function as follows (looks like you want it in RFC 2822 format, if not tweak accordingly):
Incidentally, make sure you're setting your local timezone correctly via date_default_timezone_set, etc.
以下函数对于获取字符串并获取时间戳非常有用:
将其作为时间戳后,您可以使用 date()。我不是 100% 确定 strtotime() 是否会接受该格式,但它应该接受它,因为它的格式并不含糊。
The following functions are useful for taking a string and getting a timestamp back:
After you have it as a timestamp, you can reformat it using date(). I'm not 100% sure if strtotime() would accept that format, but it should accept it because the format it isn't ambiguous.
echo date("js FY, h A", strtotime($oldDate));
echo date("js F Y, h A", strtotime($oldDate));