PHP date and time from an xml import -


i have xml file date stored in format:

<sun rise="2014-05-30t02:51:30" set="2014-05-30t18:31:22"/>

my php process value variable named $sunrise

2014-05-30t02:51:30

but timezone +2 have add 2 more hours.

the problem string. dont have idea how convert date.

since got time inside element (2014-05-30t02:51:30) use strtotime() or alternatively, use datetime + dateinterval add 2 more hours. consider example:

$sunrise = '2014-05-30t02:51:30';  $date = new datetime($sunrise); $date->add(new dateinterval('pt2h')); echo $date->format('y-m-d h:i:s'); // outputs: 2014-05-30 04:51:30  echo date('y-m-d h:i:s', strtotime($sunrise . ' +2 hours')); // outputs: 2014-05-30 04:51:30 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -