简体   繁体   English

如何增加11小时以字符串形式存储的时间

[英]How to add 11 hours to time stored as string

I have a date and timestamp in HL7 format : 201402181659 我有HL7格式的日期和时间戳:201402181659

That represents 2014 02 18 at 16:59 那代表2014 02 18在16:59

it's offset by +11:00 hours so I need to be able to add 11 hours to the date/time. 它被+11:00小时抵消了,所以我需要在日期/时间上加上11小时。 Any ideas? 有任何想法吗?

You can use DateTime::createFromFormat() to parse the string and then DateTime::modify() to add 11 hours to it: 您可以使用DateTime::createFromFormat()解析字符串,然后使用DateTime::modify()向其添加11小时:

$date = DateTime::createFromFormat('YmdHis', '201402181659');
$date->modify('+11 hours');
echo $date->format('YmdHis');

You can also use DateTime::add() with DateInterval() to add the 11 hours: 您还可以将DateTime::add()DateInterval()来添加11小时:

$date = DateTime::createFromFormat('YmdHis', '201402181659');
$date->add(new DateInterval('PT11H'));
echo $date->format('YmdHis');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM