RHDyarAP

Format tanggal indo

Oct 25th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. <?php
  2.  
  3. function dateToIndo($date,$short=false){
  4.     $BulanIndo = array("Januari", "Februari", "Maret","April", "Mei", "Juni","Juli", "Agustus", "September","Oktober", "November", "Desember");
  5.  
  6.     $bln_short = array("Jan","Feb","Mar","Apr","Mei","Jun","Jul","Agust","Sep","Okt","Nop","Des");
  7.  
  8.     $tahun = substr($date, 0, 4);
  9.     $bulan = substr($date, 5, 2);
  10.     $tgl = substr($date, 8, 2);
  11.     $jam = substr($date, 11, 8);
  12.  
  13.     if(!$short){
  14.         $result = $tgl . " " . $BulanIndo[(int)$bulan-1] . " ". $tahun." ".$jam;
  15.     }else{
  16.         $result = $tgl . " " . $bln_short[(int)$bulan-1] . " ". $tahun." ".$jam;
  17.     }
  18.  
  19.     return($result);
  20. }
  21.  
  22. //Contoh penggunaan
  23.  
  24. $date = date("Y-m-d"); //2016-02-26
  25. echo dateToIndo($date); // hasilnya adalah 26 Februari 2016
  26. echo dateToIndo($date,true); // hasilnya adalah 26 Feb 2016
  27.  
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment