PHP函数识别和解析异常时间格式?

PHP函数识别和解析异常时间格式?

问题描述:

I'm currently working with weather data feeds to assemble some accurate data. This particular feed is being pulled from Norway and has a format of 2012-01-13T19:00:00. The "T" is what throws me off.

Does anyone know if PHP will recognize this format and/or provide a function to parse this particular timestamp?

I would have thought a combo of strtotime() and date(), but apparently it only accepts English formats? I would prefer to avoid doing a regex to strip out the T but if it's necessary I'll work with it.

Many thanks for the help.

我正在使用天气数据源来汇总一些准确的数据。 这个特殊的饲料来自挪威,格式为2012-01-13T19:00:00。 “T”会让我失望。 p>

有没有人知道PHP是否会识别这种格式和/或提供解析这个特定时间戳的函数? p>

我会想到strtotime()和date()的组合,但显然它只接受英文格式? 我宁愿避免使用正则表达式删除T,但如果有必要,我会使用它。 p>

非常感谢您的帮助。 p> div >

Yes, PHP will recognize it, because that's a standardized format.

$timestamp = strtotime('2012-01-13T19:00:00');

 function isValidDateTime($dateTime)
    {
        if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $dateTime, $matches)) {
            print_r($matches);
            if (checkdate($matches[2], $matches[3], $matches[1])) {
               return true;
            }
        }
        return false;

    }