PHP格式日期 [英] PHP format date
本文介绍了PHP格式日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何强制输出日期格式:
How can I force the date format to output:
12/12/2012,1/10/2012,1/5/2012
12/12/2012, 1/10/2012, 1/5/2012
而不是
12/12/2012,01/10/2012,01/05/2012?
12/12/2012, 01/10/2012, 01/05/2012?
我的代码如下:
$adatefrom = date_create($_POST['datefrom']);
$adateto = date_create($_POST['adateto']);
$adatefrom = date_format($adatefrom, 'd/m/Y');
$adateto = date_format($adateto, 'd/m/Y');
请注意,我必须在发布后格式化日期。
Please do note that I have to format the date AFTER posting it.
推荐答案
看看PHP内置的$ date
function 这里
Have a look at the PHP built in date
function here
你会发现你的解决方案很简单:
You will find that your solution is as simple as this:
date('j/n/Y',strtotime($_POST['datefrom']));
要注意的关键事项是第一个参数中使用的字符。
The key things to note are the characters used in the first parameter.
-
j
表示无前导零 -
n
表示没有前导零的
j
represents the day without leading zerosn
represents the month without leading zeros
有很多其他选项,只需阅读文档。
There are many other options you have, just have a read through the documentation.
请注意,在Google上简单搜索PHP日期将为您找到此解决方案
这篇关于PHP格式日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文