且构网

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

如何在PHP中将标准AS400 CYMD日期格式转换为MDY?

更新时间:2023-02-12 19:41:26

CYMD 该日期具有世纪,年,月,日的格式,cyymmdd,其中1928年至1999年的c为0,2000年至2071年的c为1.

CYMD The date has the century, year, month, day format, cyymmdd, where c is 0 for years 1928 through 1999 and is 1 for years 2000 through 2071.

为您量身定做: http://ideone.com/6MQmWk

<?php

function cymdToTime($d) {
$matches = null;
preg_match('/^(\\d*)?(\\d\\d)(\\d\\d)(\\d\\d)$/', $d, $matches);
return strtotime( (($matches[1] + 19) * 100 + $matches[2]) . '-' . $matches[3] . '-' . $matches[4]);
}

echo strftime('%B %d, %Y', cymdToTime(960614)); // June 14, 1996
echo strftime('%B %d, %Y', cymdToTime(1090225)); // February 25, 2009