开发者

Convert time to readable format

I have time like this in the database

                [open_time] => 10:00:00
                [close_time] => 23:00:00

I want to convert it into readable form like 10:00am 11:00pm

I tried this:

$open = date("g:s a",$time['open_time']);

$close = date("g:sa",$time['close_time']);

I'm getting the following error:

A non well 开发者_如何学Pythonformed numeric value encountered


date expects an integer argument, the traditional Unix timestamp.

Try this:

date('g:s a', strtotime($time['open_time']));

strtotime attempts to convert a string into an integer Unix timestamp as expected by date.


If it's in your database, consider using the MySQL DATE_FORMAT() function directly in your request


The second argument needs a UNIX timestamp (epoch time):

http://php.net/manual/en/function.date.php

timestamp

The optional timestamp parameter is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time().

<?php
$t = time();
print_r($t);
print_r(date('g:i a', $t));
?>

gives

1288935001
10:30 pm
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜