简体   繁体   中英

How to change the date and time format in Laravel in full to Portuguese?

I want to change the date and time format in Laravel in full to Portuguese. Already tried to change in various ways and failed. I changed the formats using Carbon dddd, MMMM D, YYYY h: mm A instructions and couldn't

![ I want it to be like this] 1

UserController.php

$dL = [];
$dV = [];
foreach(array_reverse($stack) as $d) {
    $dL[]. = Date::parse($d)->format('dS M');

}

foreach(array_reverse($stack) as $d) {
    $date = Carbon::parse($d)->format('Y-m-d');
    $start = $date.
    ' '.
    '00:00:00';
    $end = $date.
    ' '.
    '23:59:59';
    $dC = Signal::whereBetween('created_at', [$start, $end])->get();
    $dV[]. = count($dC);
}

$data['dV'] = $dV;
$data['dL'] = $dL;

return view('user.dashboard', $data);
}

signal-all.blade.php

@php
    $p = 0;
@endphp

@foreach($signal as $k => $p)
<tr>
    <td>{{ $k + $signal->firstItem() }}</td>
    <td>{{\Jenssegers\Date\Date::parse($p->created_at)->format('dS M, Y - h:i:s A')}}</td>
    <td>{{ $p->signal->title }}</td>
    <td>{{ $p->signal->asset->name }} - {{ $p->signal->symbol->name }} - {{ $p->signal->type->name }}</td>
    <td>{{ $p->signal->frame->name }} - {{ $p->signal->status->name }}</td>

App.php

'timezone' => 'America/Sao_Paulo',

    /*
    |--------------------------------------------------------------------------
    | Application Locale Configuration
    |--------------------------------------------------------------------------
    |
    | The application locale determines the default locale that will be used
    | by the translation service provider. You are free to set this value
    | to any of the locales which will be supported by the application.
    |
    */

    'locale' => 'pt',

    /*
    |--------------------------------------------------------------------------
    | Application Fallback Locale
    |--------------------------------------------------------------------------
    |
    | The fallback locale determines the locale to use when the current one
    | is not available. You may change the value to correspond to any of
    | the language folders that are provided through your application.
    |
    */

    'fallback_locale' => 'pt',

There is a Multi-Language Supported Date Time Laravel Package for this type of Output. You may check. https://github.com/jenssegers/date

Easy to Use

use Jenssegers\Date\Date;

Date::setLocale('pt'); //For Portuguese

echo Date::now()->format('lj FYH:i:s'); // sábado 9 novembro 2019 13:45:03

echo Date::parse('-1 day')->diffForHumans(); // 1 dia atrás

I added the code and unfortunately it didn't work错误

signal-all.blade.php

@extends('layouts.user')
@section('content')

    <div class="page-body">
        <div class="row">
            <div class="col-sm-12">
                <div class="card">
                    <div class="card-header">
                        <h5>{{ $page_title }}</h5>
                        <div class="card-header-right">
                            <ul class="list-unstyled card-option">
                                <li><i class="fa fa-chevron-left"></i></li>
                                <li><i class="fa fa-window-maximize full-card"></i></li>
                                <li><i class="fa fa-minus minimize-card"></i></li>
                                <li><i class="fa fa-times close-card"></i></li>
                            </ul>
                        </div>
                    </div>
                    <div class="card-block">

                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover" id="sample_1">
                                <thead>
                                <tr>
                                    <th>SF#</th>
                                    <th>Data do sinal</th>
                                    <th>Título</th>
                                    <th>Ativos - Moeda - Tipo</th>
                                    <th>TP - Status</th>
                                    <th>Avaliação</th>
                                    <th>Açao</th>
                                </tr>
                                </thead>

                                <tbody>

                                @php $p = 0 @endphp

                                @if (\Illuminate\Support\Facades\Auth::user()->expire_time != 1 and \Carbon\Carbon::parse(\Illuminate\Support\Facades\Auth::user()->expire_time)->isPast())
                                    <tr>
                                        <td colspan="7"><h5 class="text-center">Duração do plano expirar, atualize seu plano <a href="{{ route('user-upgrade-plan') }}" class="btn text-white btn-primary font-weight-bold text-uppercase btn-min-width">Plano de atualização</a></h5></td>
                                    </tr>
                                @elseif (\Illuminate\Support\Facades\Auth::user()->plan->dashboard_status == 0)
                                    <tr>
                                        <td colspan="7"><h5 class="text-center">Sinal do painel Desative este plano, atualize seu plano <a href="{{ route('user-upgrade-plan') }}" class="btn text-white btn-primary font-weight-bold text-uppercase btn-min-width">Plano de atualização</a></h5></td>
                                    </tr>
                                @else
                                    @php $p = 0 @endphp
                                    @foreach($signal as $k => $p)
                                        <tr>
                                            <td>{{ $k + $signal->firstItem() }}</td>
                                            Date::setLocale('pt'); //For Portuguese
                                             echo Date::now()->format('l j F Y H:i:s'); // sábado 9 novembro 2019 13:45:03
                                              echo Date::parse('-1 day')->diffForHumans(); // 1 dia atrás

                                            <td>{{ $p->signal->title }}</td>
                                            <td>{{ $p->signal->asset->name }} - {{ $p->signal->symbol->name }} - {{ $p->signal->type->name }}</td>
                                            <td>{{ $p->signal->frame->name }} - {{ $p->signal->status->name }}</td>
                                            @php
                                                $total_signal = \App\SignalRating::whereSignal_id($p->signal->id)->count();
                                                $sum_signal = \App\SignalRating::whereSignal_id($p->signal->id)->sum('rating');
                                                if ($total_signal == 0){
                                                    $final_rating = 0;
                                                }else{
                                                    $final_rating = round($sum_signal / $total_signal);
                                                }
                                            @endphp
                                            <td>{!! \App\TraitsFolder\CommonTrait::getRating($final_rating) !!} - ({{ $total_signal }})</td>
                                            <td>
                                                <a href="{{ route('user-signal-view',$p->signal->custom) }}" class="btn btn-primary bold uppercase" title="Edit"><i class="fa fa-eye"></i> Visão</a>
                                            </td>
                                        </tr>
                                    @endforeach
                                @endif

                                </tbody>
                            </table>
                        </div>
                        @if ($p)
                            {{$signal->links('basic.pagination')}}
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM