
Date()
, we will get the results in English format. For example, it Date(’d F Y’)
will produce output 22 December 2016
(according to the current date). This dating format may not be very important for systems that are not used in a formal place. However, how about making a formal letter or report. Certainly, we are required to use good and correct Indonesian. The thing we need to do to change the date into Indonesian is to change the names of the months from the function
Date()
. We can do it like this.<?php
$bulan = Date(’m’);
switch ($bulan) {
case 1:
$bulan = “Januari”;
break;
case 2:
$bulan = “Februari”;
break;
case 3:
$bulan = “Maret”;
break;
case 4:
$bulan = “April”;
break;
case 5:
$bulan = “Mei”;
break;
case 6:
$bulan = “Juni”;
break;
case 7:
$bulan = “Juli”;
break;
case 8:
$bulan = “Agustus”;
break;
case 9:
$bulan = “September”;
break;
case 10:
$bulan = “Oktober”;
break;
case 11:
$bulan = “November”;
break;
case 12:
$bulan = “Desember”;
break;
default:
$bulan = Date(‘F’);
break;
}
Because we need it to be used or run in the view , it's best to be a helper .How to use it, please put the file
tanggal_helper.php
in the directory application/helpers
then add it to the helper autoload ./
| ——————————————————————-
| Auto-load Helper Files
| ——————————————————————-
| Prototype:
|
| $autoload[‘helper’] = array(‘url’, ‘file’);/
$autoload[‘helper’] = array(‘url’,‘cookie’,‘form’, ‘xss’, ‘dump’, ‘tanggal’);
After that it can be used directly in the view , controller , or model such as using a helper url
. Example:<div class=“tanda-tangan”>
<p align=“center”>Mataram, <?php echo tanggal() ?><br>
Kepala Dinas Pertanian<br>
Provinsi Nusa Tenggara Barat<br>
</p>
<br>
<br>
<br>
<p align=“center”><b><u>Ir. Hj. Budi Septiani</b></u><br>
NIP. …..
</p>
</div>
Will produce output:
Sumber: https://www.petanikode.com/codeigniter-helper-tanggal/
0 Komentar untuk "CodeIgniter Helper for Making Dates in Indonesian"
Silahkan berkomentar sesuai artikel