php - Second being lost when converting time to string -


i using cakephp 3 , php 5.6. believe cakephp may playing role in problem (ie, casting sql datetime entry it's own datetime format.)

i have sql table has series of entries containing datetime values. entered so:

2016-07-29 17:46:45 

i not doing sort of parsing of time in controller, pass on view via $this->set()

in view, can use cakephp debugger see date appears array contains time value, fixednowtime value , timezone value. time value appears so:

enter image description here

i can see second indeed included time. when try echo out, second lost no matter how attempt so.

what i've tried

here's examples of i've attempted , outputs:

1.

$dateval = date_parse($adatevalue); echo $dateval['second']; 

-no output @ all

2.

$dateval = strtotime($adatevalue); echo date('y-m-d h:i:s', $dateval); 

output (notice second lost):

2016-07-29 17:46:00 

3.

$dateval = date_parse($adatevalue['time']); echo $dateval['second']; 

output:

cannot use object of type cake\i18n\frozentime array  

attempting these in controller yields same results.

the debug kit output little deceiving, show objects debug info (__debuginfo()), array. dates aren't arrays, date/time objects error showing suggests.

the seconds being lost due attempts transform date/time object. configured en_us locale uses date format pattern doesn't output seconds (m/d/yy, h:mm a), strtotime receive datetime string 7/29/16, 5:46 pm, causing seconds lost.

if want change default output format, either format output explicitly, using example i18nformat() or format(), like

$adatevalue->i18nformat(\intldateformatter::full) 
$adatevalue->i18nformat('yyyy-mm-dd hh:mm:ss') 
$adatevalue->format('y-m-d h:i:s') 

or set/change default output format in bootstraps date/time type configuration, like

\cake\i18n\frozentime::settostringformat('yyyy-mm-dd hh:mm:ss'); 

see also


Comments