且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

转换日期格式yyyy-mm-dd => dd-mm-yyyy

更新时间:2022-03-19 01:43:35

使用 strtotime() date() code>:

Use strtotime() and date():

$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));

(请参阅 strtotime date 文档在PHP网站上)。

(see strtotime and date docs on the PHP site).

修改:请注意,这是对原始问题的快速解决方案。对于更广泛的转化,您应该真正使用 DateTime 类来解析&格式: - )

Edit: Note that this was a quick solution to the original question. For more extensive conversions, you should really be using the DateTime class to parse & format :-)