我试图找出在获取数据后如何更改节点内Date值的格式。下面的代码获取节点内的每个特定值
foreach ($degreePrograms as $key => $program) {
$programNode = _nodeLoad($program);
$variables['degree_programs'][$key]['title'] = $programNode->get('title')->value;
$variables['degree_programs'][$key]['body'] = $programNode->get('body')->value;
$variables['degree_programs'][$key]['date'] = $programNode->get('field_start_date')->value;
$variables['degree_programs'][$key]['link'] = $programNode->toUrl();
}
此代码获取节点内的Date值,并以编号的日期格式2017-09-04
返回。如何将其转换为March 04, 2017
而不是
$variables['degree_programs'][$key]['date'] = $programNode->get('field_start_date')->value;
答案 0 :(得分:1)
试试这个
$timestamp = strtotime($programNode->get('field_start_date')->value);
$new_date_format = date('F j, Y', $timestamp);