Skip to content

rajohan/DateAndTime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 

Repository files navigation

DateAndTime

This is my DateAndTime class to make it easier to do work with date and time.


Initiating

Initiate by creating a new DateAndTime() object.
__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
Example:
$time = new DateAndTime("2017-06-16 00:55:35");

Get time frame

Get a formatted time frame.
$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

Get time

Get the time difference.
$time->getTime();
Parameter Description
return string Example output: 1 year 11 months 29 days 21 hours 56 minutes 36 seconds.

Get years

Get the time difference in years.
$time->getYears();
Parameter Description
return int Example output: 1

Get months

Get the time difference in months.
$time->getMonths();
Parameter Description
return int Example output: 12

Get weeks

Get the time difference in weeks.
$time->getWeeks();
Parameter Description
return int Example output: 52

Get days

Get the time difference in days.
$time->getDays();
Parameter Description
return int Example output: 365

Get hours

Get the time difference in hours.
$time->getHours();
Parameter Description
return int Example output: 8765

Get minutes

Get the time difference in minutes.
$time->getMinutes();
Parameter Description
return int Example output: 525900

Get seconds

Get the time difference in seconds.
$time->getSeconds();
Parameter Description
return int Example output: 31554000

Get milliseconds

Get the time difference in milliseconds.
$time->getMilliseconds();
Parameter Description
return int Example output: 31554000000

Get microseconds

Get the time difference in microseconds.
$time->getMicroseconds();
Parameter Description
return int Example output: 31554000000000

Get nanoseconds

Get the time difference in nanoseconds.
$time->getNanoseconds();
Parameter Description
return int Example output: 31554000000000000

Licensed under the MIT License.

About

Date and Time

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages