Changing Time Format 09:30:00 to 9.30am

时间:2015-07-08 15:56:34

标签: php

I have times stored in the database in this format

09:30:00

And of course I can display them on the page in that format. But how do I display it in the following format?..

9.30am

I have looked for a solution but can't find anything that does just this.

2 个答案:

答案 0 :(得分:1)

使用date()函数转换时间格式。

$time = date("g:ia", strtotime("09:30:00"));

细分时间格式:

  • g - 12小时格式的小时
  • : - 冒号角色
  • i - 带有前导零的分钟
  • a - am或pm

请参阅manual

答案 1 :(得分:1)

试试这个,

$timeval = date("g:i a", strtotime("09:30:00"));