如何在PHP中将24小时转换为12小时的模式或格式 [英] How to convert 24 hours to 12 hours what pattern or format in php
本文介绍了如何在PHP中将24小时转换为12小时的模式或格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
19:24:15 06/13/2013
I need to have it converted to be in 12-hour AM/PM without the seconds. So the above time would be 7:24 PM. The date should remain in mm/dd/yyyy format. Is there an elegant way to do this in PHP (not MySQL)? Thanks!
我的尝试:
我尝试使用html标签但是没有在php中使用什么模式或格式
What I have tried:
I try in html tags but did not work what pattern or format in php
推荐答案
引用:
如何将24小时转换为12小时php中的模式或格式
How to convert 24 hours to 12 hours what pattern or format in php
格式化不仅仅是转换。
- 首先你需要将值存储在 DateTime
类型的变量中 - 然后在输出值时进行格式化。
这正是解决方案1中的2行代码。
It is formatting more than a convert.
-First you need to store the value in a variable of type DateTime
-Then it is a matter of formatting when you output the value.
This is exactly what is doing the 2 lines of code in solution 1.
尝试:
Try:
datetime = '19:24:15 06/13/2013';
回音日期('h:i A m / d / Y',strtotime(
datetime = '19:24:15 06/13/2013'; echo date('h:i A m/d/Y', strtotime(
这篇关于如何在PHP中将24小时转换为12小时的模式或格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文