mmnijas/strftime

一个兼容 PHP 8.1 及以上版本的 Laravel 扩展包,提供 strftime 功能。本包可以作为直接替换品使用,利用 IntlDateFormatter 提供地区感知的日期和时间格式化,类似于 strftime。

0.1.1 2024-09-19 03:24 UTC

This package is auto-updated.

Last update: 2024-09-21 08:11:08 UTC


README

使用 IntlDateFormatter 实现的本地化格式化 strftime(PHP 8.1 兼容)

这为 PHP 中将要移除的 strftime() 函数提供了一个跨平台替代方案。

请注意,由于使用 ICU,输出与 libc sprintf 函数之间可能略有不同。

原始代码: https://github.com/alphp/strftime.git

原作者: Fernando Herrero

目录

需求

目录

安装

Composer 安装

您可以使用 composer 将此插件安装到您的应用程序中

  • 将 mmnijas/strftime 包添加到您的项目中

      composer require mmnijas/strftime
  • 在您的项目中加载 MmNijas\strftime 函数

    <?php
      require 'vendor/autoload.php';
      use function MmNijas\strftime;

目录

手动安装

  • 下载 Strftime.php 并将其保存到项目可访问的路径。
  • 在您的项目中加载 MmNijas\strftime 函数
    <?php
      require 'Strftime.php';
      use function MmNijas\strftime;

目录

用法

  use function MmNijas\strftime;
  echo strftime('%A %e %B %Y %X', new \DateTime('2021-09-28 00:00:00'), 'fr_FR');

目录

原始用法

  \setlocale(LC_TIME, 'fr_FR.UTF-8');
  echo \strftime('%A %e %B %Y %X', strtotime('2021-09-28 00:00:00'));

目录

格式

日期

目录

星期

注意:所有周格式均为两位数,且带有前导零。

目录

月份

目录

年份

目录

时间

目录

时间和日期戳

目录

杂项

目录