0

我想在 php 中转换 12 小时时间,格式如下:05/31/2012 09:48 AM

到 24 小时时间格式:2011-11-27 11:53:36

这是我可以更改的代码行:

$time= $_POST['时间'];

4

5 回答 5

0

您可以使用strtotimethendate函数。

http://php.net/manual/en/function.date.php那里列出了所有可能的选项。

date 的第一个参数是格式,第二个参数是时间戳(通过 strtotime 获得的当前日期字符串)。

date('Y-m-d H:i:s', strtotime($your_current_date_string));

格式就在我的脑海中,并不准确。您可以在提供的链接中的表格中查找您需要的格式。

于 2012-05-31T07:59:11.607 回答
0

http://psoug.org/snippet/Convert_12_to_24_hour_time_and_vice_versa_241.htm

于 2012-05-31T08:04:44.740 回答
0

你可以使用这个:

// $time = 05/31/2012 09:48 AM
$time = $_POST['time'];    
//output new time: 2012-05-31 09:48:00
$newTime = date("Y-m-d H:i:s", strtotime($time)) );

活生生的例子

文件

于 2012-05-31T08:06:10.597 回答
0

你必须像这样使用 strtotime :

$date="05/31/2012 09:48 AM";

echo date("Y-m-d H:i:s",strtotime($date));
于 2012-05-31T08:07:24.367 回答
0

通过以下链接了解 PHP 中的日期功能

http://php.net/manual/en/function.date.php

于 2012-05-31T08:07:55.687 回答