craftplugins / carbon
该软件包已被放弃,不再维护。没有建议的替代软件包。
对于该软件包的最新版本(1.0.0),没有可用的许可证信息。
提供在 Craft 模板中访问 Carbon 的权限。
1.0.0
2020-08-06 14:11 UTC
Requires
- craftcms/cms: ^3.0.0
- nesbot/carbon: ~2
This package is auto-updated.
Last update: 2023-11-22 16:01:09 UTC
README
重要
此插件不再维护。
Carbon for Craft CMS
此插件提供在 Craft 模板中访问 Carbon 日期的权限。
使用方法
此插件简单地将日期或字符串转换为 Carbon 实例。
有关所有可用方法的详细信息,请参阅 Carbon 文档。
转换
此插件提供用于将日期转换为 Carbon 实例的功能、过滤器和变量。
{# As a function #} {% set date = carbon(entry.postDate) %} {% set date = carbon('3 days ago') %} {# As a filter #} {% set date = entry.postDate|carbon %} {% set date = 'Last Friday'|carbon %} {# As a variable #} {% set date = craft.carbon.carbon(entry.postDate) %} {% set date = craft.carbon.carbon('Saturday 5pm') %}
示例
{# Getters #} {{ date.dayName }}{# Saturday #} {{ date.locale('de').dayName }}{# Samstag #} {# Addition #} {{ date.addDay() }} {{ date.addSeconds(555) }} {# Subtraction #} {{ date.sub('2 days') }} {{ date.subWeek() }} {# Difference for humans #} {{ carbon(entry.postDate).ago() }}{# 5 days ago #} {{ carbon(entry.postDate).locale('ja_JP').ago() }}{# 5日前 #} {{ carbon('2020-01-01').diffForHumans('2020-02-02') }}{# 1 month before #}