This is my DateAndTime class to make it easier to do work with date and time.
__construct(string $date);
Parameter | Description |
---|---|
string $date | Date/time to calculate difference from current date/time. Time is optional |
Format: Y-m-d H:i:s 2017-06-16 00:55:35 or d-m-Y H:i:s | |
Remember to use date_default_timezone_set("Europe/Oslo"); to set the timezone before initiating. | |
Supported time zones: http://php.net/manual/en/timezones.php |
$time = new DateAndTime("2017-06-16 00:55:35");
$time->getTimeFrame();
Parameter | Description |
---|---|
return string | Formatted as: (Stops at first match, in the order below). |
Years >= 1: y year(s) ago | |
Months >= 1: Days == 0: m month(s) ago OR Days > 0: m month(s) d day(s) ago | |
Days >= 1: Days == 1: Yesterday OR Days > 1: d days ago | |
Hours >= 1: h hour(s) ago | |
Minutes >= 1 i minute(s) ago | |
Seconds > 30: s seconds ago | |
Seconds <= 30: Just now |
$time->getTime();
Parameter | Description |
---|---|
return string | Example output: 1 year 11 months 29 days 21 hours 56 minutes 36 seconds. |
$time->getYears();
Parameter | Description |
---|---|
return int | Example output: 1 |
$time->getMonths();
Parameter | Description |
---|---|
return int | Example output: 12 |
$time->getWeeks();
Parameter | Description |
---|---|
return int | Example output: 52 |
$time->getDays();
Parameter | Description |
---|---|
return int | Example output: 365 |
$time->getHours();
Parameter | Description |
---|---|
return int | Example output: 8765 |
$time->getMinutes();
Parameter | Description |
---|---|
return int | Example output: 525900 |
$time->getSeconds();
Parameter | Description |
---|---|
return int | Example output: 31554000 |
$time->getMilliseconds();
Parameter | Description |
---|---|
return int | Example output: 31554000000 |
$time->getMicroseconds();
Parameter | Description |
---|---|
return int | Example output: 31554000000000 |
$time->getNanoseconds();
Parameter | Description |
---|---|
return int | Example output: 31554000000000000 |