PHP将2位数年份转换为4位数年份 [英] PHP convert 2 digit year to a 4 digit year
本文介绍了PHP将2位数年份转换为4位数年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有数据来自数据库,以2位数年份格式 13
我正在将其转换为 2013
我尝试下面的代码...
I have data coming from the database in a 2 digit year format 13
I am looking to convert this to 2013
I tried the following code below...
$result = '13';
$year = date("Y", strtotime($result));
但是它返回1969年
我解决了这个问题?
推荐答案
$dt = DateTime::createFromFormat('y', '13');
echo $dt->format('Y'); // output: 2013
69
将会产生在 2069
中。 70
将导致 1970
。如果您有这样的规则,那么请按原样离开,否则,请根据自己的规则预先填写自己的世纪数据。
69
will result in 2069
. 70
will result in 1970
. If you're ok with such a rule then leave as is, otherwise, prepend your own century data according to your own rule.
这篇关于PHP将2位数年份转换为4位数年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文