From f4046082618c1aceec0d270523a7b69adbd90e4e Mon Sep 17 00:00:00 2001 From: aryapradipta9 <aryapradipta9@gmail.com> Date: Wed, 9 May 2018 13:25:37 +0700 Subject: [PATCH] adding datetime in pengumuman --- getAllBerita.php | 2 +- getAllPengumuman.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/getAllBerita.php b/getAllBerita.php index 45c2415..e55704f 100755 --- a/getAllBerita.php +++ b/getAllBerita.php @@ -37,5 +37,5 @@ while ($row = $stmt->fetch_assoc()) { $row["foto"] = $fotoarray[0]; $res[] = $row; } -echo json_encode($res, JSON_PRETTY_PRINT); +echo json_encode($res); $conn->close(); diff --git a/getAllPengumuman.php b/getAllPengumuman.php index 1f2cbb0..5826775 100755 --- a/getAllPengumuman.php +++ b/getAllPengumuman.php @@ -10,12 +10,30 @@ * @link http://pear.php.net/package/komunitas-pmo */ +function tanggal_indo($tanggal) +{ + $hari = array ( 1 => 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab', 'Min'); + + $bulan = array (1 => 'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Agu', 'Sep', + 'Okt', 'Nov', 'Des'); + + $split = explode('-', $tanggal); + $tgl_indo = $split[2] . ' ' . $bulan[ (int)$split[1] ] . ' ' . $split[0]; + $num = date('N', strtotime($tanggal)); + return $hari[$num] . ', ' . $tgl_indo; +} + require 'dbConnect.php'; +header('Content-Type: application/json'); $stmt = $conn->query("SELECT * FROM `pengumuman` ORDER BY `tanggal` DESC"); $count = $stmt->num_rows; $res = array(); while ($row = $stmt->fetch_assoc()) { + $fullTanggal = new DateTime($row['tanggal']); + $date = tanggal_indo(date_format($fullTanggal, "Y-m-d")); + $time = date_format($fullTanggal, "H:i"); + $row['tanggal'] = $date . ' ' . $time; $res[] = $row; } echo json_encode($res); -- GitLab