如何从PHP中的datetime获取AM / PM [英] How to get AM/PM from a datetime in PHP

查看:99
本文介绍了如何从PHP中的datetime获取AM / PM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在变量中有日期时间。我的格式是 08/04/2010 22:15:00 。我想像 10.15 PM 显示。如何在PHP中执行此操作?

I have a date time in a variable. My format is 08/04/2010 22:15:00. I want to display this like 10.15 PM. How to do this in PHP?

提前感谢

推荐答案

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

You need to convert it to a UNIX timestamp (using strtotime) and then back into the format you require using the date function.

例如:

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

这篇关于如何从PHP中的datetime获取AM / PM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆