我需要帮助将JSON
日期转换为PHP
日期格式
我正在尝试找到一种将日期转换为m-d-Y
的{{1}}格式的方法。
我得到
php
这是我的控制器
{
"result":"ok",
"ret":
{"count":7,
"setFirstResult":0,
"setMaxResults":5,
"data":[
{"id":218,
"name":"AAA",
"mes":"",
"updatetime":
{"date":"2019-09-18 12:25:42.000000",
"timezone_type":3,
"timezone":"Asia\/Taipei"
}
}
如何使用public function showMeg(Request $request, $page)
{
$entityManager = $this->getDoctrine()->getEntityManager();
$per = 5;
$start = ($page-1)*$per;
$query = $entityManager->createQueryBuilder()
->select("r")
->from("MegBundle:message", "r")
->setFirstResult($start)
->setMaxResults($per);
$data = $query->getQuery()->getArrayResult();
$paginator = new Paginator($query, $fetchJoinCollection = false);
$count = count($paginator);
$pages = ceil($count/$per);
return new JsonResponse(['result' => 'ok', 'ret' => ['data' => $data]]);
}
以这种格式转换正常时间。例如php
答案 0 :(得分:0)
您可以像这样转换它:
$timezone = "Asia/Taipei";
$dateTime = "2019-09-18 12:25:42.000000";
try {
$timezone = new \DateTimeZone($timezone);
$date = new \DateTime($dateTime, $timezone);
echo $date->format('m-d-Y');
} catch (Exception $e) {
echo 'Error converting date'
}