你能帮我么?我需要改变
2017-12-31 11:45:00
至
2017-12-31T11:45
使用PHP功能。
我需要这个datetime-local格式来输入一个输入值。
这可能会为你做到:
<?php
$date = '2017-12-31 11:45:00';
$newdate = date('Y-m-d\TH:i', strtotime($date));
echo $newdate; // 2017-12-31T11:45
;?>
有关strtotime
的文档:http://php.net/manual/en/function.strtotime.php
注意:
strtotime
最大日期是'19 Jan 2038 03:14:07 UTC'。
新解决方案:PHP 5> = 5.2.0,PHP 7
请考虑使用新的DateTime函数:http://php.net/manual/en/datetime.construct.php
示例新DateTime:
<?php
$d = new DateTime("9999-12-31");
$d->format("Y-m-d"); // "9999-12-31"
$d = new DateTime("0000-12-31");
$d->format("Y-m-d"); // "0000-12-31"
$d = new DateTime("-9999-12-31");
$d->format("Y-m-d"); // "-9999-12-31"
?>
这可以使用PHP提供的DateTime对象非常简单地完成
<?php
$dt = DateTime::createFromFormat('Y-m-d H:i:s', '2017-12-31 11:45:00');
$newFormat = $dt->format('Y-m-d\TH:i');
echo $newFormat;
结果:
2017-12-19T11:45