Blog for Learning

| lesson material | material summary | questions and answers | definitions | types and examples | other information | materi pelajaran | ringkasan materi | pertanyaan dan jawaban | definisi | jenis-jenis dan contoh-contoh | informasi lainnya |

Powered by Blogger.

Pages

CodeIgniter Helper for Making Dates in Indonesian

When we make an automatic date with a function 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 .

<? php
/ **
* Helpher to print dates in Indonesian format
*
* CodeIgniter @package
* @category Helpers
* @author Ardianta Pargo (ardianta_pargo@yhaoo.co.id)
* @link https://gist.github.com/ardianta/ba0934a0ee88315359d30095c7e442de
* @version 1.0
* /
/ **
* Function to change the month of English into Indonesian
* @param int month number, Date ('m')
* @return the moon name string in Indonesian
* /
if ( ! function_exists ( ' month ' )) {
function month () {
$ month = Date ( ' m ' );
switch ( $ month ) {
case 1 :
$ month = " January " ;
break ;
case 2 :
$ month = " February " ;
break ;
case 3 :
$ month = " March " ;
break ;
case 4 :
$ month = " April " ;
break ;
case 5 :
$ month = " May " ;
break ;
case 6 :
$ month = " June " ;
break ;
case 7 :
$ month = " July " ;
break ;
case 8 :
$ month = " August " ;
break ;
case 9 :
$ month = " September " ;
break ;
case 10 :
$ month = " October " ;
break ;
case 11 :
$ month = " November " ;
break ;
case 12 :
$ month = " December " ;
break ;
default :
$ month = Date ( ' F ' );
break ;
}
return $ month ;
}
}
/ **
* Function to make dates in Indonesian format
* @Param void
* @return string current date format (example: December 22, 2016)
* /
if ( ! function_exists ( ' dated ' )) {
function date () {
$ date = Date ( ' d ' ) . " " . month () . " " . Date ( ' Y ' );
return $ date ;
}
}
raw viewdated_helper.php hosted with ❤by GitHub

How to use it, please put the file tanggal_helper.php in the directory application/helpersthen 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 urlExample:
<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:
The output of date format in Indonesian on CodeIgniter
Sumber: https://www.petanikode.com/codeigniter-helper-tanggal/
0 Komentar untuk "CodeIgniter Helper for Making Dates in Indonesian"

Silahkan berkomentar sesuai artikel

 
Template By Kunci Dunia
Back To Top