PHP中的日期格式 [英] Date formatting in PHP

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

问题描述

我的日期格式如Tue Jan 05 11:08:27 +0000 2010,我想在PHP中将其格式转换为yyyy-mm-dd 00:00。



我该怎么做?

解决方案

使用strtotime将其转换为PHP日期对象)然后输出date()



编辑



尝试:

  $ time = strtotime('Tue Jan 05 11:08:27 +0000 2010'); 
echo date(Y-m-d h:i,$ time);

Y = 4位数年份
m = 2位数月份(带前导0)
d = 2位数月份(前导0)



h = 12小时时间(前0)
i =分钟(带前导0)



http://php.net/manual/ en / function.date.php
所有格式化选项


I've a date formatted like "Tue Jan 05 11:08:27 +0000 2010" and I want to convert it's format to "yyyy-mm-dd 00:00" in PHP.

How can I do that?

解决方案

convert it to a PHP date object with strtotime() then output it with date()

EDIT

Some more detail; try:

$time = strtotime('Tue Jan 05 11:08:27 +0000 2010');
echo date("Y-m-d h:i", $time);

Y = 4 digit year m = 2 digit month (with leading 0) d = 2 digit month (with leading 0)

h = 12 hour time (leading 0) i = minutes (with leading 0)

http://php.net/manual/en/function.date.php for all the formatting options

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

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