I have a timestamp in PHP, so I'm using Carbon extension to manage everything that is related with date, time,etc. Now I have for example a hour 23:00 or 20:00 with this extension how I can convert that to AM and PM format?

推荐答案

I'm not sure if there is a out-of-the-box helper method for this, but you could always use the format method, which defers to the base class method DateTime::format().

Example:

$now = Carbon::now();
echo $now->format('g:i A');

This will echo out something like 5:17 PM.

giA看起来是随机的,但参数列表可以在这里找到:http://php.net/manual/en/function.date.php

g: 12-hour format of an hour without leading zeros

i:带有前导零的分钟

A:大写的前梅里迪姆和后梅里迪姆

Laravel相关问答推荐

警告:构建Reaction App(VITE)后无法解码下载的字体警告

使用两个日期之间的范围获取两列之间的记录,同时搜索过滤条件

Laravel:在行的子集上同步多对多

如何使用动态翻译键翻译 Laravel硬编码字符串(还有 1 个错误)..(验证异常类)

从主类别模型 laravel 中获取子类别翻译

Laravel - 加载常见的页眉和页脚以查看

Eloquent: hasNot 带参数

如何监控 Laravel 队列是否正在运行?

如何在 laravel 中使用 str_replace

使用 Eloquent (Laravel) 在 Group By 之前排序

使用 ModelNotFoundException

Laravel - 自定义时间戳列名称

Laravel Eloquent:计算总价的最佳方法

Laravel 5.4 有时验证规则不起作用

Class类 App\Http\Controllers\Auth\Request 不存在.

如何在 Laravel 或 Redis 中取消排队的作业(job)

在 laravel 的测试套件中只运行一个单元测试

Laravel 5.2 验证错误未出现在Blade中

如何在没有日志(log)、没有信息的情况下调试 Laravel 错误 500

以编程方式而不是从 CLI 运行 Laravel 5 seeder