fyre/formatter

一个格式化库。

v3.0.5 2024-08-18 05:32 UTC

This package is auto-updated.

Last update: 2024-09-18 05:37:11 UTC


README

FyreFormatter 是一个免费的、开源的用于 PHP 的格式化库。

目录

安装

使用 Composer

composer require fyre/formatter

在 PHP 中

use Fyre\Utility\Formatter;

方法

货币

将值格式化为货币字符串。

  • $value 是表示要格式化值的字符串或数字。
  • $options 是一个包含格式化选项的数组。
    • $locale 是表示区域的字符串,默认为 Formatter 的默认区域。
    • $currency 是表示货币的字符串,默认为 Formatter 的默认货币。
$currency = Formatter::currency($value, $options);

日期

DateTime 格式化为日期字符串。

  • $value 是一个 DateTime
  • $options 是一个包含格式化选项的数组。
    • $locale 是表示区域的字符串,默认为 Formatter 的默认区域。
    • $timeZone 是表示时区的字符串,默认为 Formatter 的默认时区。
    • $format 是表示格式的字符串,默认为 TypeParser 的默认日期用户格式。
$date = Formatter::date($value, $options);

日期/时间

DateTime 格式化为日期/时间字符串。

  • $value 是一个 DateTime
  • $options 是一个包含格式化选项的数组。
    • $locale 是表示区域的字符串,默认为 Formatter 的默认区域。
    • $timeZone 是表示时区的字符串,默认为 Formatter 的默认时区。
    • $format 是表示格式的字符串,默认为 TypeParser 的默认日期时间用户格式。
$datetime = Formatter::datetime($value, $options);

获取默认货币

获取默认货币。

$defaultCurrency = Formatter::getDefaultCurrency();

获取默认区域

获取默认区域。

$defaultLocale = Formatter::getDefaultLocale();

获取默认时区

获取默认时区。

$defaultTimeZone = Formatter::getDefaultTimeZone();

数字

将值格式化为数字字符串。

  • $value 是表示要格式化值的字符串或数字。
  • $options 是一个包含格式化选项的数组。
    • $locale 是表示区域的字符串,默认为 Formatter 的默认区域。
$number = Formatter::number($value, $options);

百分比

将值格式化为百分比字符串。

  • $value 是表示要格式化值的字符串或数字。
  • $options 是一个包含格式化选项的数组。
    • $locale 是表示区域的字符串,默认为 Formatter 的默认区域。
$percent = Formatter::percent($value, $options);

设置默认货币

设置默认货币。

  • $currency 是表示货币代码的字符串。
Formatter::setDefaultCurrency($currency);

设置默认区域

设置默认区域。

  • $locale 是表示区域的字符串。
Formatter::setDefaultLocale($locale);

设置默认时区

设置默认时区。

  • $timeZone 是表示时区的字符串。
Formatter::setDefaultTimeZone($timeZone);

时间

DateTime 格式化为时间字符串。

  • $value 是一个 DateTime
  • $options 是一个包含格式化选项的数组。
    • $locale 是表示区域的字符串,默认为 Formatter 的默认区域。
    • $timeZone 是表示时区的字符串,默认为 Formatter 的默认时区。
    • $format 是表示格式的字符串,默认为 TypeParser 的默认时间用户格式。
$time = Formatter::time($value, $options);