DateTime

Type
Class
Namespace
Craft
Inherits
Craft\DateTime » DateTime
Since
1.0

Class DateTime

See also http://craftcms.com

View source

Public Methods

MethodDescription
__toString()
atom()
cookie()
createFromFormat()Creates a new \Craft\DateTime object (rather than \DateTime)
createFromString()Creates a new DateTime object from a string.
day()
diff()
format()
iso8601()
localeDate()
localeTime()
month()
mySqlDateTime()
nice()Returns a nicely formatted date string.
rfc1036()
rfc1123()
rfc2822()
rfc3339()
rfc822()
rfc850()
rss()
uiTimestamp()Returns a UI-facing timestamp.
w3c()
w3cDate()
year()

__toString()

Signature

public string __toString ( )

atom()

Signature

public string atom ( )

Signature

public string cookie ( )

createFromFormat()

Creates a new \Craft\DateTime object (rather than \DateTime)

View source

Arguments

  • $format (string)
  • $time (string)
  • $timezone (mixed) – The timezone the string is set in (defaults to UTC).

Returns

Craft\DateTime

Signature

public static Craft\DateTime createFromFormat ( $format, $time, $timezone = null )

createFromString()

Creates a new DateTime object from a string. Supports the following formats:

  • An array of the date and time in the current locale's short formats
  • All W3C date and time formats (http://www.w3.org/TR/NOTE-datetime)
  • MySQL DATE and DATETIME formats (http://dev.mysql.com/doc/refman/5.1/en/datetime.html)
  • Relaxed versions of W3C and MySQL formats (single-digit months, days, and hours)
  • Unix timestamps

View source

Arguments

  • $date (string, array)
  • $timezone (string, null) – The PHP timezone identifier that $date is set to, if not already specified in $date. Defaults to 'UTC'.
  • $setToSystemTimeZone (boolean) – Whether to set the resulting DateTime object to the system timezone.

Returns

Craft\DateTime, null, false

Signature

public static Craft\DateTime, null, false createFromString ( $date, $timezone = null, $setToSystemTimeZone = true )

day()

Signature

public string day ( )

diff()

View source

Arguments

Returns

Craft\DateInterval

Signature

public Craft\DateInterval diff ( $datetime2, $absolute = false )

format()

View source

Arguments

  • $format (string)
  • $timezone (mixed) – The timezone to output the date in (defaults to the current app timezone).

Returns

string

Signature

public string format ( $format, $timezone = null )

iso8601()

Signature

public string iso8601 ( )

localeDate()

Signature

public string localeDate ( )

localeTime()

Signature

public string localeTime ( )

month()

Signature

public string month ( )

mySqlDateTime()

Signature

public string mySqlDateTime ( )

nice()

Returns a nicely formatted date string.

View source

Returns

string

Signature

public string nice ( )

rfc1036()

Signature

public string rfc1036 ( )

rfc1123()

Signature

public string rfc1123 ( )

rfc2822()

Signature

public string rfc2822 ( )

rfc3339()

Signature

public string rfc3339 ( )

rfc822()

Signature

public string rfc822 ( )

rfc850()

Signature

public string rfc850 ( )

rss()

Signature

public string rss ( )

uiTimestamp()

Returns a UI-facing timestamp.

  • If the date/time is from today, only the time will be retuned in a localized format (e.g. “10:00 AM”).
  • If the date/time is from yesterday, “Yesterday” will be returned.
  • If the date/time is from the last 7 days, the name of the day will be returned (e.g. “Monday”).
  • Otherwise, the date will be returned in a localized format (e.g. “12/2/2014”).

View source

Returns

string

Signature

public string uiTimestamp ( )

w3c()

Signature

public string w3c ( )

w3cDate()

Signature

public string w3cDate ( )

year()

Signature

public string year ( )

Constants

ConstantDescription
DATEFIELD_12HOUR
DATEFIELD_24HOUR
MYSQL_DATETIME
UTC
W3C_DATE