org_heigl / date-formatter
可扩展库,用于使用Zend-Frameworks日期常量格式化日期时间
1.1.0
2016-03-25 15:59 UTC
Requires
- org_heigl/filefinder: ^1.0
Requires (Dev)
- phpunit/phpunit: ^5.2
This package is auto-updated.
Last update: 2024-09-23 09:14:58 UTC
README
可扩展库,用于使用Zend-Frameworks日期常量格式化日期时间
安装
composer require org_heigl/date-formatter
用法
use Org_Heigl\DateFormatter\FormatterFacade as Formatter; $date = new DateTime('2013-12-03 12:23:34', new DateTimeZone('Europe/Berlin')); echo Formatter::format($date, 'PDF'); // Prints "20131203122334+01'00'"
目前有以下格式化程序可用
- ATOM
- COOKIE
- RFC_822
- RFC_850
- RFC_1036
- RFC_1123
- RFC_3339
- RSS
- W3C
- MYSQL
扩展
您可以通过创建一个实现Org_Heigl\DateFormatter\Formatter\FormatterInterface
接口的类来添加自己的格式化程序。然后,这个类可以直接像以下示例一样使用
use Org_Heigl\DateFormatter\DateFormatter as Formatter; $formatter = new Formatter(new MyCoolClassImplementingFormatterInterface()); $date = new DateTime('2013-12-03 12:23:34', new DateTimeZone('Europe/Berlin')); echo $formatter->format($date); // Prints whatever you formatted the given date to ;)
为了能够使用它与FormatterFacade
一起,您必须像以下示例一样向类声明包含格式化程序的文件夹
use Org_Heigl\DateFormatter\FormatterFacade as Formatter; // Announce the Folder containing your formatter to the class Formatter::addFormatterFolder('/absolute/Path/To/Your/Formatter/Folder'); $date = new DateTime('2013-12-03 12:23:34', new DateTimeZone('Europe/Berlin')); echo Formatter::format($date, 'WhateverYouCalledYourFormatter'); // Prints WhateverYourFormatterDoes ;)
自定义格式化程序将始终调用而不是默认格式化程序。因此,当您在添加的文件夹中有“PDF”格式化程序时,将调用该格式化程序而不是默认格式化程序!