我必须在日期格式中添加条件,以便在分钟为00时不显示:00。
例如(使用当前格式)
Tuesday, January 24, 2017 - 9:15 am
Tuesday, January 24, 2017 - 9:00 am
应该显示(我正在寻找的)
Tuesday, January 24, 2017 - 9:15 am
Tuesday, January 24, 2017 - 9 am
谢谢!
答案 0 :(得分:0)
我使用field.api.php中的hook_field_attach_preprocess_alter挂钩实现了解决方案
我们的应用程序中已经有一个名为“local”的模块,我可以将此代码添加到。
/**
* Implements hook_field_attach_preprocess_alter
*/
function local_field_attach_preprocess_alter(&$variables, $context) {
global $language;
foreach ($variables['content'] as $field_name => $field) {
// remove minutes formating if at 00 on field type datestamp.
if (isset($field['#field_type']) && $field['#field_type'] === 'datestamp') {
$tmp_date = $variables['content'][$field_name][0]['#markup'];
switch ($language->language) {
case 'en':
$variables['content'][$field_name][0]['#markup'] = str_replace(':00', '', $tmp_date);
break;
case 'fr':
$variables['content'][$field_name][0]['#markup'] = str_replace('h 00', 'h', $tmp_date);
break;
default:
break;
}
}
}
}