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.

8
  • You could use strftime() function with correct locale. Commented Apr 4, 2017 at 7:13
  • 2
    use carbon library. Commented Apr 4, 2017 at 7:20
  • @Autista_z how to do that for example ?? Commented Apr 4, 2017 at 7:28
  • @Gaurav if i use carbon i got local this time right ? cant convert from DB right ? or how to use ? Commented Apr 4, 2017 at 7:29
  • 2
    Add the following line to the aliases array in the config/app.php: 'Carbon' => 'Carbon\Carbon' And you need to add use Carbon; every class where you want to use it. {{ $quotes->created_at->format('d m Y i'); Commented Apr 4, 2017 at 7:47

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

13 Comments

if i use windows so what should i do ? where should i put setlcoale bro ?
setlocale is an php function. You mean how to install locale in Windows?
in step 1 and 2 it used sudo.. so should i use cmd ?
btw how can i use on blade ? strftime("%a %d %b %Y", strtotime(date('Y-m-d'))) on this <?php echo date("d F Y", strtotime($keluhan->tanggal)); ?>
<?php echo strftime("%a %d %b %Y", strtotime($keluhan->tanggal)); ?>
|
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

Comments

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.