查询中的日期格式更改 [英] Date Format Change in Query
本文介绍了查询中的日期格式更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PHP JSON作为android中的API.我正在使用下面的代码从MYSQL数据中获取消息.它的工作正常,但日期格式显示为 YYYY-MM-DD..但是我想像 DD-MM-YYYY .解决方案.这里有人可以解决我的问题吗?
I am using PHP JSON as API in android. I am taking news from MYSQL data with below code. Its working fine but date format is showing as YYYY-MM-DD. But I want get it like DD-MM-YYYY. I have searched lot of but not found any solution. Can anybody here can solve my issue ?
<?php
$response = array();
require 'db.php';
$query = "SELECT * FROM news where order by id desc";
$result = mysqli_query($conn,$query);
if (mysqli_num_rows($result) > 0) {
$response["news"] = array();
while ($row = $result->fetch_assoc()) {
$news= array();
$news["id"] = $row["id"];
$news["title"] = $row["title"];
$news["description"] = $row["description"];
$news["news_date"] = $row["news_date"];
array_push($response["news"], $news);
}
$response["success"] = 1;
// echoing JSON response
//echo json_encode($response);
echo json_encode($response['news']);
} else {
$response["success"] = 0;
echo json_encode($response);
}
谢谢
推荐答案
更改此行
$news["news_date"] = date("d-m-Y" ,strtotime ($row["news_date"]) );
这篇关于查询中的日期格式更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文