[英]Drupal7 format_date
Somebody could help me to how to change string date with format_date function. 有人可以帮我看看如何使用format_date函数更改字符串日期。 Here is my code
$datesql = format_date("2014-04-02 11:11:31", 'custom', 'Ym-d'); drupal_set_message(t('date '.$datesql));
这是我的代码
$datesql = format_date("2014-04-02 11:11:31", 'custom', 'Ym-d'); drupal_set_message(t('date '.$datesql));
$datesql = format_date("2014-04-02 11:11:31", 'custom', 'Ym-d'); drupal_set_message(t('date '.$datesql));
I suppose drupal to show this message "date 2014-04-02", but drupal just show the message "date", not $datesql. 我想drupal显示此消息“date 2014-04-02”,但是drupal只显示消息“date”,而不是$ datesql。 What is wrong in my code.
我的代码有什么问题。 Thanks
谢谢
Function "format_date" expects first parameter to be a timestamp, not a string. 函数“format_date”要求第一个参数是时间戳,而不是字符串。 Try to wrap this first parameter with "strtotime" function and you will get a better result.
尝试使用“strtotime”函数包装第一个参数,您将获得更好的结果。
PS: do not include a variable in the first parameter of the "t" function. PS:不要在“t”函数的第一个参数中包含变量。 This could result in a lot of translatable strings.
这可能会产生很多可翻译的字符串。 Pass it in the second parameter with "@myvar" as key.
将它传递给第二个参数,并将“@myvar”作为键。 Check the "t" function documentation for more details.
有关详细信息,请查看“t”功能文档。
try this 尝试这个
$date = new DateTime('2014-04-02 11:11:31');
$da = $date->format('Y-m-d H:i:s');
drupal_set_message('date '.$da,'status');
format_date() is use a covert a date in drupal created date not a convert a custom date format_date()使用隐藏drupal创建日期的日期而不是转换自定义日期
format_date($node->created, 'custom', 'Y-m-d');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.