php - 如何从 PHP 中的日期时间获取 AM/PM

我在变量中有一个日期时间。我的格式是 08/04/2010 22:15:00。我想像 10.15 PM 一样显示它。如何在 PHP 中做到这一点?

最佳答案

您需要将其转换为 UNIX 时间戳(使用 strtotime),然后使用 date 转换回您需要的格式。功能。

例如:

$currentDateTime = '08/04/2010 22:15:00';
$newDateTime = date('h:i A', strtotime($currentDateTime));

https://stackoverflow.com/questions/3404699/

相关文章:

perl - 快速到达 YYYY-mm-dd HH :MM:SS in Perl

python - Python中用户友好的时间格式?

c# - 如何将 double 格式设置为四舍五入到最接近的美元的货币?

c# - 您何时使用 StringBuilder.AppendLine/string.Format

c++ - 相当于 %02d 与 std::stringstream?

c# - 使用任意字符串向左或向右填充 string.format(不是 padleft 或 pad

sql - 有哪些免费的 SQL 格式化工具?

c# - 在 C# 中格式化 double 输出

python - 如何自动格式化一些 Python 代码以正确格式化?

java - 转换给定时区的日期/时间 - java