我还没有找到一个简单的方法来做到这一点,很少有地方,地址日期格式与2年。我读过strtotime(),它实际上只处理4位数的年份或美国格式--这对我没有帮助。
最后,我通常会将字符串分解成一个数组,在一年前添加20,然后用它进行转换,但这看起来真的很麻烦。
我辛辛苦苦地做着这个例子:http://php.net/manual/en/function.strtotime.php#100144,无法让它工作.看起来很简单..。然后我读了笔记;
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. If, however, the year is given in a two digit format and the separator is a dash (-), the date string is parsed as y-m-d.
是否有一种更经济的方式来处理这些日期,或者我将永远被迫执行3-4行的转换每次?
日期: 19/04/18
日期: 18/06/18
日期: 19/06/18
日期: 19/06/18
日期: 19/06/18
发布于 2018-07-19 04:30:49
将dd/mm/yy转换为php中日期的最简单和最简单的方法?
使用日期::createFromFormat()
<?php
$date = '24/03/83';
//
echo date_create_from_format('d/m/y', $date)->format('Y-m-d');或
<?php
$date = '24/03/83';
//
echo DateTime::createFromFormat('d/m/y', $date)->format('Y-m-d');结果:
1983-03-24如果年份是Y,请使用1983,所有格式见上面的手动链接。
https://stackoverflow.com/questions/51414304
复制相似问题