1

I'm from Indonesia, and I want to show date with Indonesian language format but what I've got was English language format.

Example format was 23 march 2017 (english)

I want to get like this one 23 Maret 2017 (Indonesia) so the problem of mine is language.

Can you give me some idea ? this is my example code

<?php echo date("d F Y", strtotime($row->tanggal_pelaksanaan)); ?>

and

Tgl: @foreach ($tindak as $tindakan)
     {{ date("d F Y", strtotime($tindakan->target_verifikasi)) }}
     @endforeach

Please Kindly help me. thank you.

linktoahref
  • 7,812
  • 3
  • 29
  • 51
Christianus Andre
  • 237
  • 2
  • 4
  • 13

4 Answers4

2
  1. See if the locale is installed in your server.

    You can list all the locale in your server by issuing the command

    locale -a

  2. Install your locale. Indonesian locale, I believe is id_ID by issuing the command. The list of locale is obtained from this answer https://stackoverflow.com/a/28357857/5808894

    sudo locale-gen id_ID

    sudo update-locale

  3. Set locale using the method setlocale

    setlocale(LC_TIME, 'id_ID');

  4. Either use Carbon or strftime to output the localized date

    strftime("%a %d %b %Y", strtotime(date('Y-m-d')))

    OR

    Carbon\Carbon::parse('23-03-2017 11:23:45')->formatLocalized('%A %d %B %Y');

    outputs Kamis 23 Maret 2017

Community
  • 1
  • 1
linktoahref
  • 7,812
  • 3
  • 29
  • 51
2
$dateName = Carbon::now()->locale('id')->isoFormat('LL'); //return 17 Mei 2020 

$dateName = Carbon::now()->locale('id')->isoFormat('LLLL');  //return Minggu, 17 Mei 2020 pukul 10.21

Try this code and you can check on https://carbon.nesbot.com/docs/#api-localization

0

Laravel Eloquent allows you format from the model so you can do

$model->created_at->format('Y-m-d')

To do this you should add

$protected $dates = [
    'created_at',
    'updated_at',
    // add other column names here that you want as Carbon Date
];

This will then mutate the columns to be a easily manipulated date object

see https://laravel.com/docs/5.4/eloquent-mutators#date-mutators for further details

James
  • 671
  • 5
  • 17
0

You cannot depends on server locale, because most of application was running on their own devices with their own locale format. You can installing the locale format for your own device but not for others because they have their locale timezone.

Use another method like:

{{ date('d-m-y', strtotime($example->start_date))}}

The code above will change

yyyy-mm-dd

format to

d-m-y

2019-05-01 to 01-05-19

Or

{{ date('l, d-m-y', strtotime($example->start_date))}}

Ouput:

Friday, 01-05-2019

Hope it helps.

Kris
  • 109
  • 1
  • 11