class DateTime extends DateTime implements IntegerRepresentation, FloatRepresentation, StringRepresentation, ArrayRepresentation (View source)

the NoreSources\DateTime class extends the built-in \DateTIme class by adding more capabilities to be constructed ad exported to various data types.

Constants

FORMAT_YEAR_LEAP

Leap year indicator

FORMAT_YEAR_ISO8601

ISO-8601 week-numbering year.

This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.

FORMAT_YEAR_DIGIT_2

A two digit representation of a year

FORMAT_YEAR_NUMBER

A full numeric representation of a year, 4 digits

FORMAT_YEAR_DAY_NUMBER

Day of the year, starting from zero.

FORMAT_MONTH_ALPHA_3

Abbreviated month name, based on the locale

FORMAT_MONTH_NAME

Full month name, based on the locale

FORMAT_MONTH_DIGIT_2

Two digit representation of the month

FORMAT_MONTH_NUMBER

Month number without leading zero

FORMAT_MONTH_DAY_COUNT

Number of day in the current month

FORMAT_WEEK_DIGIT_2

A numeric representation of the week of the year, starting with the first Monday as the first week

FORMAT_WEEK_DAY_ISO8601

ISO-8601 numeric representation of the day of the week.

1 = Monday 7 = Sunday

FORMAT_WEEK_DAY_NUMBER

Numeric representation of the day of the week.

0 = Sunday 6 = Saturday

FORMAT_WEEK_DAY_EN_ALPHA_2

English ordinal suffix for the day of the month, 2 character

FORMAT_DAY_ALPHA_3

A textual representation of a day, three letters

FORMAT_DAY_NAME

A full textual representation of the day

FORMAT_DAY_DIGIT_2

Two-digit day of the month (with leading zeros)

FORMAT_DAY_NUMBER

Day of the month without leading zeros

FORMAT_HOUR_24_DIGIT_2

Two digit representation of the hour in 24-hour format

FORMAT_HOUR_24_PADDED

Hour in 24-hour format, with a space preceding single digits

FORMAT_HOUR_12_DIGIT_2

Two digit representation of the hour in 12-hour format

FORMAT_HOUR_12_PADDED

Hour in 12-hour format, with a space preceding single digits.

1 through 12

FORMAT_SWATCH_TIME

Swatch internet time

0 to 999

FORMAT_EPOCH_OFFSET

Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

FORMAT_HOUR_AM_UPPERCASE

UPPER-CASE 'AM' or 'PM' based on the given time

FORMAT_HOUR_AM_LOWERCASE

lower-case 'am' or 'pm' based on the given time

FORMAT_MINUTE_DIGIT_2

Two digit representation of the minute.

00 through 59

FORMAT_SECOND_DIGIT_2

Two digit representation of the second.

00 through 59

FORMAT_MILLISECOND

Millisecondes

FORMAT_MICROSECOND

Microsecondes

FORMAT_TIMEZONE_OFFSET

Timezone offset in seconds

FORMAT_TIMEZONE_GMT_OFFSET_COLON

GMT offset (colon)

FORMAT_TIMEZONE_GMT_OFFSET_COLON_Z

GMT offset (colon) or Z for UTC offset PHP 8+

FORMAT_TIMEZONE_GMT_OFFSET

GMT offset

FORMAT_TIMEZONE_NAME

Time zone identifier

Ex: Europe/Berlin

FORMAT_TIMEZONE_DST

Daylight indicator

0 or 1

FORMAT_TIMEZONE_ALPHA_3

The time zone abbreviation

FORMAT_TIMESTAMP_ISO8601

ISO 8601 date

FORMAT_TIMESTAMP_RFC2822

RFC 2822 formatted date

FORMAT_DESCRIPTION_LABEL

Timestamp format token label

FORMAT_DESCRIPTION_RANGE

Timestamp format token value range

FORMAT_DESCRIPTION_STRFTIME

Strict equivalent format token for the strftime() function

FORMAT_DESCRIPTION_DETAILS

Timestamp format token additional informations

Methods

__construct(string|integer|float $time = null, DateTimeZone $timezone = null)

No description

string
__toString()

No description

static integer
toJulianDayNumber(DateTimeInterface $dateTime, boolean $utc = true)

Julian day representation of the given DateTime

integer
getJulianDayNumber(boolean $utc = true)

Julian day representation of the given DateTime

static number
toJulianDay(DateTimeInterface $dateTime, boolean $utc = true)

Full julian day and time representation of the given DateTime

number
getJulianDay()

Full julian day and time representation of the given DateTime

setJulianDay(float $jd)

Set the date and time from a julian day time

array
getArrayCopy()

Timestamp data informations

static DateTime
createFromArray(array $array, boolean $baseClass = true)

Create a DateTime from a DateTime description array

static boolean
isDateTimeStateArray(array $array)

Indicate if the given array can be used to create a DateTime using DateTime::__set_state() magic method.

integer
getIntegerValue()

No description

float
getFloatValue()

No description

static mixed|array|ArrayAccess|ContainerInterface|Traversable|array
getFormatTokenDescriptions(string|null $token = null)

Description of PHP date() function tokens

static DateTimeZone
getUTCTimezone()

No description

Details

__construct(string|integer|float $time = null, DateTimeZone $timezone = null)

Parameters

string|integer|float $time Timestamp

  • string
  • A \DateTime::_construct compatible timestamp format
  • integer
  • UNIX time since ephoc
  • float
  • Julian day
DateTimeZone $timezone Time zone hint. Use this time zone ONLY if the $time does not provide time zone information

string __toString()

Return Value

string The string representation of the class instance

static integer toJulianDayNumber(DateTimeInterface $dateTime, boolean $utc = true)

Julian day representation of the given DateTime

Parameters

DateTimeInterface $dateTime DateTime to convert
boolean $utc Indicates if the DateTime time zone must be converted to UTC before calculating the julian day number.

Return Value

integer Julian day number

See also

https://en.wikipedia.org/wiki/Julian_day#Converting_Gregorian_calendar_date_to_Julian_Day_Number

integer getJulianDayNumber(boolean $utc = true)

Julian day representation of the given DateTime

Parameters

boolean $utc Indicates if the DateTime time zone must be converted to UTC before calculating the julian day number.

Return Value

integer Julian day number

See also

https://en.wikipedia.org/wiki/Julian_day#Converting_Gregorian_calendar_date_to_Julian_Day_Number

static number toJulianDay(DateTimeInterface $dateTime, boolean $utc = true)

Full julian day and time representation of the given DateTime

Parameters

DateTimeInterface $dateTime DateTime to convert
boolean $utc Indicates if the DateTime time zone must be converted to UTC before calculating the julian day number.

Return Value

number Julian day number and time

See also

https://en.wikipedia.org/wiki/Julian_day#Finding_Julian_date_given_Julian_day_number_and_time_of_day

number getJulianDay()

Full julian day and time representation of the given DateTime

setJulianDay(float $jd)

Set the date and time from a julian day time

Parameters

float $jd Julian day value Julian day

array getArrayCopy()

Timestamp data informations

Return Value

array Array representation of the class instance

static DateTime createFromArray(array $array, boolean $baseClass = true)

Create a DateTime from a DateTime description array

Parameters

array $array An associative array with one of the following key/value pairs

  • DateTime state. The same array format output by var_export().
    • date: Timestamp without timezone information
    • timezone_type: Timezone type
      1. UTC offset (ex. +0100)
      2. Timezone abbreviation (ex. CET)
      3. Timezone identifier (@see https://www.php.net/manual/en/class.datetimezone.php)
    • timezone: Timezone value
  • DateTimestamp and format
    • time Timestamp
    • format: Format string
    • timezone: (optional) \DateTimeZone or valid timezone identifier
boolean $baseClass Return a built-in \DateTime instance. Otherwise, return a \NoreSources\DateTime (with no particular benefits)

Return Value

DateTime

Exceptions

InvalidArgumentException

static boolean isDateTimeStateArray(array $array)

Indicate if the given array can be used to create a DateTime using DateTime::__set_state() magic method.

Parameters

array $array

Return Value

boolean

integer getIntegerValue()

Return Value

integer Integer representation of the class instance

float getFloatValue()

Return Value

float Float representation of the class instance

static mixed|array|ArrayAccess|ContainerInterface|Traversable|array getFormatTokenDescriptions(string|null $token = null)

Description of PHP date() function tokens

Parameters

string|null $token PHP date() token

Return Value

mixed|array|ArrayAccess|ContainerInterface|Traversable|array

static DateTimeZone getUTCTimezone()

Return Value

DateTimeZone