PHP日期格式化 [英] PHP date formatting
问题描述
我想从以下格式转换日期: 01/07/09
到这个 jan 07,09
I want to transform a date from this format: 01/07/09
to this jan 07,09
.
如何在PHP中执行?
推荐答案
使用 strptime
解析您的价值,然后 date
以您想要的格式输出:
Use strptime
to parse the value you've got, then date
to output it in the format you want:
echo date("M d,y", strptime("01/07/09", "d/m/y"));
如果您在Windows上,或使用PHP的版本,其中 strptime
不可用(< PHP 5.1.0),然后使用 strtotime
,但请注意确保您的日期为美国英语格式(即01/07/09表示2009年1月7日,不是2009年7月1日)
If you're on Windows, or using a version of PHP where strptime
is not available (< PHP 5.1.0), then use strtotime
instead, but be careful to make sure your date is in a US English format (i.e. "01/07/09" means January 7th 2009, not 1st July 2009).
另外,如果你真的想要 jan
,而不是 Jan
,然后使用 strtolower
:
Also, if you really want jan
, rather than Jan
, then use strtolower
:
echo strtolower(date("M d,y", strptime("01/07/09", "d/m/y"));
这篇关于PHP日期格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!