1

I have a date/time field, when I save it as 1:00:00 AM, it displays in the edit form as 1:00 am, however when I do a get of that field value in my module with $posted_date=$static_media->get('field_pup_posted')->getValue(); , it comes out as`Array ( [0] => Array ( [value] => 2017-06-14T05:00:00 )

)`

Why is it being stored as a 5 when it should be a 1? and how can i get it programatically in the correct time zone

2

drupal stores in UTC have to convert this to current time zone

$dt=new \DateTime($changed_date, new \DateTimeZone('UTC'));
$dt->setTimeZone(new \DateTimeZone('America/New_York'));
$correct_date =  $dt->format('Y-m-d H:i:s');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.