Search code examples
laraveltimephp-carbon

formatLocalized, format minutes


I'm reading an Excel file with:

$data = Excel::selectSheetsByIndex(0)->load($archivo_procesar, function($reader) {})->get()->toArray();

Then Im trying to get the time (hours:minutes:00) from my "time" with

$time = $data["time"]->formatLocalized('%H:%m:00');

When I do dd($time); I get "05:11:00". 05 is ok for the hours, 00 is ok because I need always 00 as seconds, but 11 is not the minutes is the month of that date, but I need to read the minutes. I tried with '%H:%i:00' or '%H:%mm:00' but I'm getting errores. How should I used the formatLocalized for to get the minutes ok?


Solution

  • As you can see in Carbon formatLocalized method :

    $formatted = strftime($format, strtotime($this->toDateTimeString()));

    It uses strftime and as we can see in the documentation, the two digit representation of the minute is %M.

    So you should use $time = $data["time"]->formatLocalized('%H:%M:00');.