php datetime-local格式替换你能帮帮我吗? [关闭]

问题描述 投票:-2回答:2

你能帮我么?我需要改变

2017-12-31 11:45:00 

2017-12-31T11:45

使用PHP功能。

我需要这个datetime-local格式来输入一个输入值。

php string date replace
2个回答
0
投票

这可能会为你做到:

<?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"

?>

0
投票

这可以使用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
© www.soinside.com 2019 - 2024. All rights reserved.