halo gan langsung aja ni ane share caranya, ni klu agan bingung menampilkan format tanggal indonesianya...
Berikut Source Code nya ..
<?php
function indonesian_date ($timestamp = '', $date_format = 'l, j F Y') {
if (trim ($timestamp) == '')
{
$timestamp = time ();
}
elseif (!ctype_digit ($timestamp))
{
$timestamp = strtotime ($timestamp);
}
# remove S (st,nd,rd,th) there are no such things in indonesia :p
$date_format = preg_replace ("/S/", "", $date_format);
$pattern = array (
'/Mon[^day]/','/Tue[^sday]/','/Wed[^nesday]/','/Thu[^rsday]/',
'/Fri[^day]/','/Sat[^urday]/','/Sun[^day]/','/Monday/','/Tuesday/',
'/Wednesday/','/Thursday/','/Friday/','/Saturday/','/Sunday/',
'/Jan[^uary]/','/Feb[^ruary]/','/Mar[^ch]/','/Apr[^il]/','/May/',
'/Jun[^e]/','/Jul[^y]/','/Aug[^ust]/','/Sep[^tember]/','/Oct[^ober]/',
'/Nov[^ember]/','/Dec[^ember]/','/January/','/February/','/March/',
'/April/','/June/','/July/','/August/','/September/','/October/',
'/November/','/December/',
);
$replace = array ( 'Sen','Sel','Rab','Kam','Jum','Sab','Min',
'Senin','Selasa','Rabu','Kamis','Jumat','Sabtu','Minggu',
'Jan','Feb','Mar','Apr','Mei','Jun','Jul','Ags','Sep','Okt','Nov','Des',
'Januari','Februari','Maret','April','Juni','Juli','Agustus','Sepember',
'Oktober','November','Desember',
);
$date = date ($date_format, $timestamp);
$date = preg_replace ($pattern, $replace, $date);
$date = "{$date}";
return $date;
}
?>
- save dengan nama fungsi tanggal_indonesia.php
- nanti di form yang ingin di tampilkan tinggal di include trus di panggil ....
contohnya ni :
$tanggal = "2016-10-04";
echo indonesian_date ($tanggal);
- atau jika mau ambil data tannggal nya dari database seperti ini gan ..
<?php $date = $data['date'];
echo indonesian_date ($date); ?>
- ok cukup jelas kan gan... cukup sekian dulu ya nanti di share lgi klu ada yang penting
Monday, October 3, 2016
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment