phplaravellaravel-5.8php-carbon

Can't return localized AM/PM format of time using Carbon formatLocalized method?


I want to return Arabic localized time to be like this

so i set carbon locale in boot method of AppServiceProvider class

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {

        Carbon::setLocale(config('app.locale'));
    }
}

and then use carbon to parse the fetched time from database and use formatLocalized method with format to show hours and minutes like this

$time = Carbon::parse('09:00:00')->formatLocalized('%I:%M %p');

but it return time like this

Is there is any way to achieve this?


Solution

  • After deep searching using of isoFormat method achieve what I want

    $time = Carbon::parse('09:00:00')->isoFormat('h:mm a');
    

    then the output will be