我正在尝试以JSON格式将日期发送到我的Android设备。此外,时间为24小时格式。如何将其更改为12小时格式?
PHP
<?php
$sql = "SELECT * from news Order by n_date Desc";
$con = mysqli_connect($server_name, $mysql_user, $mysql_pass, $db_name);
$result = mysqli_query($con, $sql);
$response = array();
while ($row = mysqli_fetch_array($result)) {
array_push($response, array("title" => $row[2], "content" => $row[3], "n_date" => $row[4]));
}
echo json_encode(array("news_response" => $response));
mysqli_close($con);
?>
JSON回复:
{"news_response":[{"title":"news","content":"content","n_date":"2016-11-12 10:47:23"}]}
我正在尝试将2016-11-12
转换为November 12, 2016 10:47:23
之类的内容。我该怎么做?
我在网上找不到任何例子。
答案 0 :(得分:2)
:
echo (new DateTime('2016-11-12 10:47:23'))->format('F d, y GA:i:s');
MySQL中的:
SELECT concat(MONTHNAME(date),' ', DAY(date), ' ', TIME(date)) from news;
答案 1 :(得分:1)
您可以使用echo date('F j, Y H:i:s',strtotime('2016-11-12 10:47:23'));
答案 2 :(得分:0)
使用PHP date_format()
$date = date_create("2016-11-12 10:47:23");
echo date_format($date, 'g:ia \o\n l jS F Y');
答案 3 :(得分:0)
/* Hide image with class-a by default */
img.class-a {
display: block;
}
/* showing it in windows 10 only */
.windows.windows10 img.class-a {
display: block;
}