阅读(2057) (0)

CodeIgniter4 Date Helper

2020-08-14 16:56:02 更新

日期帮助程序文件包含协助处理日期的功能。

加载此助手

使用以下代码加载此帮助程序:

helper('date');

可用功能

提供以下功能:

now([$timezone = NULL])

参数: $timezone (string) – 时区
返回: UNIX时间戳
返回类型: int

根据配置文件中的“时间参考”设置,以UNIX时间戳记返回当前时间,该时间参考服务器的本地时间或任何PHP支持的时区。如果您不打算将主时间参考设置为任何其他PHP支持的时区(如果您运行一个允许每个用户设置自己的时区设置的站点,通常会这样做),则与PHP time()函数相比,使用此函数没有任何好处。

echo now('Australia/Victoria');

如果未提供时区,它将time()根据 time_reference设置返回。

timezone_select([$class = '', $default = '', $what = DateTimeZone::ALL, $country = null])

参数: $class (string) – 应用于选择字段的可选类
$default (string) – 初始选择的默认值
$what (int) – DateTimeZone类常量(请参见listIdentifiers
$country (string) –两个字母的ISO 3166-1兼容国家/地区代码(请参阅listIdentifiers
返回: Preformatted HTML select field
返回类型: string

生成可用时区的选择表单字段(可选地由$ what和$ country过滤)。您可以提供一个选项类别以应用于该字段,以简化格式化,并提供一个默认的选定值。

echo timezone_select('custom-select', 'America/New_York');

先前在CodeIgniter 3中找到的许多功能date_helper已移至I18n CodeIgniter 4中的模块。