Hazaar
Date
The date/time class

This class can be used to manage date and time values and perform date arithmetic.

Example

$date = new Hazaar\Date('next tuesday');
echo $date; //Echo's a timestamp such as '2013-01-15 11:00:00.0'

Timezones

It is possible to set the timezone globally for all date/time functions and classes.

For example, to set your timezone to 'Australia/ACT', in your application.ini file add the line:

pre. php.date.timezone = Australia/ACT

See the PHP Manual for a "list of valid timezones":http://php.net/manual/en/timezones.php.

If a timezone is not set in the application.ini file, nor is one set in the global PHP configuration then as a last ditch effort the Date class will default to UTC. This is because not having an ini setting in date.timzone will cause a PHP runtime error.

Extends
\DateTime
Summary
MethodsPropertiesConstants
No constants
Properties
Static
$calendar
$calendar
Static
$date_format
$date_format
Global format for date part
Static
$default_format
$default_format
$instance_format
$instance_format
Static
$time_format
$time_format
Global format for time part
$usec
$usec
Methods
__construct()
__construct($datetime = null, $timezone = null)

The Date class constructor takes two values. A datetime declaration and a timezone. Both are optional. If now datetime is specified then the current datetime is used. If no timezone is specified then the default timezone will be used.

__export()
__export()
__tostring()
__tostring() : string
Magic method to output the datetime value as a string.

Uses the Date::timestamp() method.

add()
add($interval, $return_new = false) : Date
Add a date/time interval to the current date/time.

See the PHP documentation on how to use the "DateInterval":http://au2.php.net/manual/en/class.dateinterval.php object.

age()
age($precision = 0) : integer
Returns the age in years of the date with optional precision
compare()
compare($date, $include_time = false)
Compare the current date with the argument
date()
date() : string
Return the date part formatted by the global date format.
datetime()
datetime() : string
Return the date and time.

This will use the global date and time formats and concatenate them together, separated by a space.

day()
day()
Returns the objects current day
daysInMonth()
daysInMonth() : int
Returns the number of days in the current month.
diff()
diff($timestamp, $return_seconds = false) : \DateInterval|int
Returns the difference between the current date/time value and the value supplied as the first argument.

Normally this method will return a \DateInterval object which is the default for the \DateTime class. However this functionality has been extended with the $return_seconds parameter which will instead return an integer value indicating the difference in whole seconds.

end()
end() : Date
Returns the end time of the current date as a Date object.
firstOfMonth()
firstOfMonth() : Date
Returns the first day of the current month as a Date object.
firstOfWeek()
firstOfWeek() : Date
Returns the first day of the current week as a Date object.
firstOfYear()
firstOfYear() : Date
Returns the first day of the current year as a Date object.
formatTZ()
formatTZ($format, $timezone = 'UTC') : string
Return the date time value using a format string for a specified timezone
fuzzy()
fuzzy($precise = false, $date_threshold_days = 30) : string
Return a fuzzy diff between the current time and the Date value.
Static
getLocaleData()
getLocaleData($locale) : \array|boolean
Get locale data for a specified locale

Data included is what is returned by PHP's localeconv() function.

Static
getLocaleDateFormat()
getLocaleDateFormat($locale) : \boolean|null|string
Retrieve a date format for a specific locale

This will return something like DMY to indicate that the locale format is date, month followed by year.

These formats are not meant to be used directly in date functions as different date functions use different format specifiers and we won't even attempt to support all of them here.

getSQLDate()
getSQLDate() : string
Get the current datetime value as an SQL compliant formatted string.
hour()
hour()
Returns the objects current hour(
lastOfMonth()
lastOfMonth() : Date
Returns the last day of the current month as a Date object.
lastOfWeek()
lastOfWeek() : Date
Returns the last day of the current week as a Date object.
lastOfYear()
lastOfYear() : Date
Returns the last day of the current year as a Date object.
minute()
minute()
Returns the objects current minute
month()
month()
Returns the objects current month
sec()
sec() : int
Returns the current datetime value as epoch (seconds passed since 1970-01-01).
second()
second()
Returns the objects current second
setFormat()
setFormat($format)
setTimezone()
setTimezone($timezone = null) : boolean
Set the timezone for the date object

Setting this will cause the date and time to be output using the specified timezone. If a timezone is not given then the default system timezone will be used. This is a good way to convert a date of another timezone into the current default system timezone.

start()
start() : Date
Returns the start time of the current date as a Date object.
sub()
sub($interval, $return_new = false) : Date
Subtract a date/time interval from the current date/time.

See the PHP documentation on how to use the "DateInterval":http://au2.php.net/manual/en/class.dateinterval.php object.

time()
time() : string
Return the time part formatted by the global time format.
timestamp()
timestamp() : string
Get the timestamp formatted as a string.

This will use the global date and time formats and concatenate them together, separated by a space.

usec()
usec() : int
Return the microsecond part of the datetime value.

This will more than likely always be 0 (zero) unless specified in the constructor.

year()
year()
Returns the objects current year
Powered by Scroly.io Generated: Thursday, October 3rd 2019 at 2:45pm