如何设置像'2018-08-31'这样的日期字符串

问题描述 投票:0回答:2

我有一个来自tt_content的日期字符串'2018-08-31',想要像这样转换它:'2018年8月31日' - 我如何让它工作?

我试过这个:

10 = TEXT
10 {
    wrap = |
    data.field = tx_mask_cnt_news_item_date  // field in tt_content, is '2018-08-31'
    strftime = %e %B %Y
}

但这会显示当前日期(以所需格式)。有人可以给我一个暗示吗?

typo3 typoscript
2个回答
1
投票

试试这个:

10 = TEXT
10 {
    wrap = |
    field = tx_mask_cnt_news_item_date
    strftime = %e %B %Y
}

data.field = tx_mask_cnt_news_item_datetx_mask_cnt_news_item_date的内容设置为data的值,这将导致任何结果。直接在field对象中的TEXTtx_mask_cnt_news_item_date的内容设置为TEXT对象的值,然后将通过strftime传递。


1
投票

我找到了一个解决方案:使用strtotime = 1,字符串将转换为时间戳,然后strftime将按预期工作:

10 = TEXT
10 {
    wrap = |
    field = tx_mask_cnt_news_item_date  // field in tt_content, is '2018-08-31'
    strtotime = 1
    strftime = %e %B %Y
}
© www.soinside.com 2019 - 2024. All rights reserved.