<?php
function tgl($date = "", $s ="", $p = "-"){
  $date = (empty($date)) ? date("Y-m-d H:i:s") : $date;
  $s 		= (empty($s)) ? "default" : $s;

  $bulan = array(1 => "Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","Nopember","Desember");
  $hari = array(1 => "Senin","Selasa","Rabu","Kamis","Jumat","Sabtu","Minggu");

  switch ($s) {
    case 'default':
      $tgl = explode(" ", $date);
      $tgl1 = explode("-", $tgl[0]);
      return $tgl1[2].$p.$tgl1[1].$p.$tgl1[0]." ".@$tgl[1];
    break;
    case 'tgl_bulan':
      $tgl = explode(" ", $date);
      $tgl1 = explode("-", $tgl[0]);
      return $tgl1[2]." ".$bulan[(int)$tgl1[1]]." ".$tgl1[0];
    break;
    case 'full':
      $tgl = explode(" ", $date);
      $no = date('N',strtotime($date));
      $tgl1 = explode("-", $tgl[0]);
      return $hari[$no].", ".$tgl1[2]." ".$bulan[(int)$tgl1[1]]." ".$tgl1[0]." ".@$tgl[1];
    break;
  }
}

echo tgl(); // waktu sekarang
echo "<br>";

echo tgl("", "", "/"); // waktu sekarang dengan pemisah yang dapat di ubah.
echo "<br>";
echo "<br>";

echo tgl("2019-06-01"); //output 01-06-2019
echo "<br>";

echo tgl("2019-06-01", "", "/"); //output 01/06/2019
echo "<br>";
echo "<br>";

echo tgl("2019-06-01 13:15:00"); //output 01-06-2019 13:15:00
echo "<br>";
echo tgl("2019-06-01 13:15:00", "", "/"); //output 01/06/2019 13:15:00
echo "<br>";
echo "<br>";

echo tgl("", "tgl_bulan"); //output tanggal dan bulan hari ini
echo "<br>";

echo tgl("", "full"); //output tanggal dan waktu hari ini

?>

Comment