我正在尝试从 XML 文件中解析日期,并以与原始日期相同的格式返回字符串中的日期,但8 小时前除外。
原始日期采用以下格式:
'yyyy-mm-ddThh:mm:ss.ffff'
,因此日期始终是固定长度。
示例:'2013-10-06T14:00:40.1000'
在这种情况下使用 date_parse() 和 date_modify() 函数的合适方法是什么?
当前代码:
public function setTimeSeriesStartDate(){
//FIXME
//replace T with space to make it parsable by date_parse()
$tempDate = $this->date;
$tempDate[10] = ' ';
$parsedDate = new DateTime(date_parse($tempDate));
$parsedDate->modify('-'.$this->daysBeforeEvent.' day');
$farmattedDate=$parsedDate->format('Y-m-d H:i:s');
if($formattedDate){
$this->timeSeriesStartDate= $formattedDate;
$this->timeSeriesStartDate[10]='T';
}
else {$this->timeSeriesStartDate = $this->date;}
}
Github 上的对应问题:https ://github.com/felakuti4life/Seismokraft/issues/1