在节点内获取值后更改日期值格式

时间:2017-06-30 04:03:42

标签: drupal

我试图找出在获取数据后如何更改节点内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;

1 个答案:

答案 0 :(得分:1)

试试这个

 $timestamp = strtotime($programNode->get('field_start_date')->value);
 $new_date_format = date('F j, Y', $timestamp);