Class Date
Updated: Sunday, 07 August 2016
Date and time handling.
Table of Content
Date Formatter
$my_date = '2014-04-12 05:05:05';
echo Date::format($my_date, 'Y/m/d');
The code above will outputs “2014/04/12”.
Read more about date formatting patterns here.
This class also can accept time format that looks like this, which is usually derived from the file name parts:
2014-04-12-05-05-05
Date Extractor
Added since version 1.0.2
.
Extract the date input into some commonly used formatted date. Returned as array:
$date = Date::extract('2014-04-12-05-05-05');
Results:
$date = array(
'unix' => 1397253905,
'W3C' => '2014-04-12T05:05:05+07:00',
'GMT' => '2014-04-11 22:05:05',
'year' => '2014',
'year_short' => '14',
'month' => '04',
'day' => '12',
'month_number' => 4,
'day_number' => 12,
'month_name' => 'April',
'day_name' => 'Saturday',
'month_name_short' => 'Apr',
'day_name_short' => 'Sat',
'hour' => '05',
'hour_12' => '05',
'hour_24' => '05',
'minute' => '05',
'second' => '05',
'AM_PM' => 'AM',
'FORMAT_1' => 'Saturday, 12 April 2014',
'FORMAT_2' => 'Saturday, April 12, 2014',
'FORMAT_3' => '2014/04/12 05:05:05',
'FORMAT_4' => '2014/04/12 05:05:05 AM',
'FORMAT_5' => '05:05',
'FORMAT_6' => '05:05 AM'
);
Optional to output only the desired format:
echo Date::extract('2014-04-12-05-05-05', 'W3C');
Results:
2014-04-12T05:05:05+07:00
Date Ago Calculator
Added since version 1.0.4
.
Returned as array.
$date = Date::ago('2011-04-21 08:45:12');
Results:
$date
│
├── year: 3 Years
├── month: 3 Months
├── day: 24 Days
├── hour: 1 Hour
├── minute: 52 Minutes
└── second: 25 Seconds