Reputation: 510
I'm using the niceShort
function in the Time Helper in Cake to display some times from my database. It works wonderfully, but it would be great to be able to have niceShort
use 12 hour time instead of 24. Is there a way to do this without modifying the helper?
Upvotes: 2
Views: 875
Reputation: 2136
As cakephp's format() uses PHP's strftime() formatting options. You can use
%I:%M %p or %r
echo $this->Time->format($news['News']['modified'],'%d/%m/%Y %I:%M %p');
it will format for example: 21:34:17 to 09:34:17 PM. You can read more here.
Upvotes: 0
Reputation: 510
I still wanted to be able to use the nice
and niceShort
functions, so I modified the Time helper and moved it into app/views/helpers.
.
Upvotes: 1
Reputation: 2712
To make a 12-hour time, simply do this in your view:
<?php echo $time->format('g:la', $string); ?>
For a list of all of the different formatting options, see:
http://php.net/manual/en/function.date.php
In other words, my above example (g:la)
would output 4:45pm
Upvotes: 1