【问题标题】:Typo3 RealURL: Format datetimeTypo3 RealURL:格式化日期时间
【发布时间】:2014-12-17 22:46:06
【问题描述】:

假设以下 Typo3 RealURL 设置:

'news' => array(
        array(
                'GETvar' => 'tx_news_pi1[action]',
        ),
        array(
                'GETvar' => 'tx_news_pi1[controller]',
        ),
        array(
                'GETvar' => 'tx_news_pi1[news]',
                'lookUpTable' => array(
                        'table' => 'tx_news_domain_model_news',
                        'id_field' => 'uid',
                        'alias_field' => 'CONCAT(title, "-", datetime)',
                        'addWhereClause' => ' AND NOT deleted',
                        'useUniqueCache' => 1,
                        'useUniqueCache_conf' => array(
                                'strtolower' => 1,
                                'spaceCharacter' => '-',
                        ),
                        'languageGetVar' => 'L',
                        'languageExceptionUids' => '',
                        'languageField' => 'sys_language_uid',
                        'transOrigPointerField' => 'l10n_parent',
                        'autoUpdate' => 1,
                        'expireDays' => 180,
                ),
        ),
),

关于这一行:'alias_field' => 'CONCAT(title, "-", datetime)',

我需要格式化时间戳。

我已经尝试过的:'alias_field' => 'CONCAT(title, "-", DATE_FORMAT(datetime, '%Y-%m-%d'))',

+++ 更多文本 +++ 更多文本 +++ 更多文本 +++

【问题讨论】:

  • 您介意显示所需的输出和您当前的输出吗?
  • 所需输出:http://www.example.net/news/article/my-article-2014-10-22/ 当前输出:http://www.example.net/news/article/-aed1a14f04/

标签: php datetime typo3 datetime-format realurl


【解决方案1】:

您需要使用 MySQL 日期格式化函数:

'alias_field' => 'CONCAT(title, "-", DATE(FROM_UNIXTIME(datetime)))',

这会将 Unix 时间戳转换为 MySQL DateTime 并将其格式化为仅日期。

请参阅 MySQL 的 Date and Time 函数以获取更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 1970-01-01
    • 2011-11-20
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多