php - Date format should be in cst -
i have date in our database "2014-03-06 16:23:33". wanted display "mar 06, 2014 04:23:33 pm cst". using cakephp.
eg:
$this -> html -> cdate ($courselog['courselog']['completed_time'],'datetimes');
thanks in adv.
plz answer asap.
update
while stated wasn't sure if cakephp had specific helper this, i'm sure not.
own documentation mentions datetime
class, , link php docs
, github search called cdate
shows empty, cdata
entirely different anyway...
as follow comment, i'll delete, completeness add here:
i don't know if cakephp has specific helper this,
$date = new datetime($yourdatestring); $date->format(date_rfc820);
should close. compose own format according need, or check the predefined constants readily available.
ok, date_rfc850
constant isn't exact match of format looking for, , string manipulations (as in series of substr
, explode
-implode
calls) tedious , messy , amateurish. look @ format parameters!
suspect you're looking this:
$date = new datetime($courselog['courselog']['completed_time']); $asstring = $date->format('m d, y h:i:s e');
perhaps it's safer create datetime
instance format know, , expect. know how string formatted, can use static method datetime::createfromformat
, too:
$date = datetime::createfromformat( 'y-m-d h:i:s', //yyyy-mm-dd hh:mm:ss format $courselog['courselog']['completed_time']//the string parse ); $asstring = $date->format('m d, y h:i:s e'); echo $asstring, php_eol;
as can see from codepad, works perfectly...
the format explained:
m
: short textual representation of month,f
gives full monthd
: 2 digit (with leading zeroes) representation of day, changej
drop leading zeroesy
: 4 digit year, opposedy
, gives 2 digitsh
: 12 hour leading zeroes,g
drops leading zeroes. capitalize either format , 24 hour versioni
: minutes, leading zeroess
: seconds, leading zeroesa
: or pm, changea
am or pme
: time-zone identifier, alternativest
(timezone abbreviation) oro
,p
(both difference gmt in hours,p
adds colon between hours , minutes (+0400 vs +04:00)
bottom line, php comes datetime
object offers solid way work dates , times, i'd suggest use core object. whatever cakephp offers, it'll wrapper around the datetime
, related classes
Comments
Post a Comment