Date
in package
Class for managing dates and times.
Tags
Table of Contents
- $lang : mixed
- __construct() : mixed
- Class constructor.
- age() : string
- คืนค่าอายุเป็นข้อความ ปี เดือน วัน
- compare() : array<string|int, mixed>
- Calculates the difference between two dates (e.g., age).
- dateName() : string
- Converts a number to the name of the day in the current language.
- format() : string
- Converts a time to a date in the specified format.
- monthName() : string
- Converts a number to the name of the month in the current language.
- parse() : array<string|int, mixed>|bool
- Parses a date string into an array.
- timeAgo() : string
- Converts a date to a human-readable time ago format
- timeDiff() : int
- Returns the time difference in milliseconds.
Properties
$lang
private
static mixed
$lang
Methods
__construct()
Class constructor.
public
__construct() : mixed
Return values
mixed —age()
คืนค่าอายุเป็นข้อความ ปี เดือน วัน
public
static age(string $date) : string
Parameters
- $date : string
Return values
string —compare()
Calculates the difference between two dates (e.g., age).
public
static compare(string|int $begin_date, istring|int $end_date) : array<string|int, mixed>
Returns the number of days (can be negative), years, months, and days [days, year, month, day].
Parameters
- $begin_date : string|int
-
The start date or birth date (Unix timestamp or date in the format YYYY-m-d)
- $end_date : istring|int
-
The end date or today's date (Unix timestamp or date in the format YYYY-m-d)
Tags
Return values
array<string|int, mixed> —dateName()
Converts a number to the name of the day in the current language.
public
static dateName(int $date[, bool $short_date = true ]) : string
Returns the name of the day (e.g., Sunday...Saturday).
Parameters
- $date : int
-
0-6
- $short_date : bool = true
-
true (default) for short day name format (e.g., อ.), false for full month name format (e.g., อาทิตย์)
Tags
Return values
string —format()
Converts a time to a date in the specified format.
public
static format(int|string $time[, string $format = null ]) : string
Returns the date and time in the specified format.
Parameters
- $time : int|string
-
int for Unix timestamp, string for Y-m-d or Y-m-d H:i:s format (if not specified or empty, it means today)
- $format : string = null
-
The desired format of the date (if not specified, it uses the format from the language file DATE_FORMAT)
Tags
Return values
string —monthName()
Converts a number to the name of the month in the current language.
public
static monthName(int $month[, bool $short_month = true ]) : string
Returns the name of the month (e.g., January...December).
Parameters
- $month : int
-
1-12
- $short_month : bool = true
-
true (default) for short month name format (e.g., มค.), false for full month name format (e.g., มกราคม)
Tags
Return values
string —parse()
Parses a date string into an array.
public
static parse(string $date) : array<string|int, mixed>|bool
Returns an array containing year, month, day, hour, minute, second, or an empty array if it's not a date.
Parameters
- $date : string
-
The date string to parse
Return values
array<string|int, mixed>|bool —timeAgo()
Converts a date to a human-readable time ago format
public
static timeAgo(string $date) : string
Parameters
- $date : string
Return values
string —timeDiff()
Returns the time difference in milliseconds.
public
static timeDiff( $firstTime, $lastTime) : int