oneseven9955/dateparser
最新稳定版本:0.1.0
Composer 安装命令:
composer require oneseven9955/dateparser
包简介
DateParser is a parser that can interpret date strings in various formats.
README 文档
README
This PHP package is a date string parser that can interpret date strings in various formats. It is implemented using a finite state machine. With this package, developers can easily parse date strings without relying on external libraries or tools.
Getting Started
use OneSeven9955\DateParser\DateParser; use OneSeven9955\DateParser\ParseException; // Strict parse: an invalid date string will cause ParseException try { $datetime = DateParser::from('30/04/2025')->parse(); // DateTime { date: 2015-04-30 00:00:00.0 UTC (+00:00) } } catch (ParseException $ex) { printf("Unable to parse the date: %s\n", $ex->getMessage()); } // Silent parse: an invalid date string will cause null as return value $datetimeOrNull = DateParser::from('30#04#2025')->parseSilent(); // null
Supported Date Formats
The time part is being omitted.
YYYY-MM-DD
- 2014-04-26
MM/DD/YY
- 3/31/2014
- 03/31/2014
- 08/21/71
- 8/1/71
YYYY/MM/DD
- 2014/3/31
- 2014/03/31
MM.DD.YY
- 3.31.2014
- 03.31.2014
- 08.21.71
- 2014.03
- 2014.03.30
Textual Month
- oct 7, 1970
- oct 7, '70
- oct. 7, 1970
- oct. 7, 70
- October 7, 1970
- October 7th, 1970
- 7 oct 70
- 7 oct 1970
- 03 February 2013
- 1 July 2013
- 2013-Feb-03
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-30