DateTime

Type
Class
Namespace
Craft
Inherits
Craft\DateTime » DateTime (opens new window)
Since
1.0

Class DateTime

See also http://craftcms.com

View source (opens new window)

# Public Methods

Method Description
__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 (opens new window)

Arguments

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 (opens new window)

Arguments

Returns

Craft\DateTime, null (opens new window), false (opens new window)

Signature

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

# day()

Signature

public string day ( )

# diff()

Signature

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

# format()

View source (opens new window)

Arguments

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

Returns

string (opens new window)

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 (opens new window)

Returns

string (opens new window)

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 (opens new window)

Returns

string (opens new window)

Signature

public string uiTimestamp ( )

# w3c()

Signature

public string w3c ( )

# w3cDate()

Signature

public string w3cDate ( )

# year()

Signature

public string year ( )

# Constants

Constant Description
DATEFIELD_12HOUR
DATEFIELD_24HOUR
MYSQL_DATETIME
UTC
W3C_DATE