Version: v0.7.1 - Beta.  We welcome contributors & feedback.

Date.format

Date.format($format = 'iso8601') -> string

Description

Format a date object per PHP DateTime format.

The names of days and months will be returned according to the current locale, which can be set via setLocale.

Examples:

$date.format('Y-m-d')
//= '2021-08-23'

$date.format('M Y')
//= 'Feb 2021'

$date.format('Y-m-d H:i:s')
//= '2021-08-23 16:23:50'

Predefined Formats

Optionally, you may pass in the name of a predefined format:

$date.format('sql')
//= '2021-08-23 15:48:07'

Format Example
sql 2021-08-23 15:48:07
rss Mon, 23 Aug 2021 15:48:07 +0300
w3c 2021-08-23T15:48:07+03:00
atom 2021-08-23T15:48:07+03:00
cookie Monday, 23-Aug-2021 15:48:07 UTC
iso8601 2021-08-23T15:48:07+0300
rfc822 Mon, 23 Aug 21 15:48:07 +0300
rfc850 Monday, 23-Aug-21 15:48:07 UTC
rfc1036 Mon, 23 Aug 21 15:48:07 +0300
rfc1123 Mon, 23 Aug 2021 15:48:07 +0300
rfc7231 Mon, 23 Aug 2021 15:48:07 GMT
rfc2822 Mon, 23 Aug 2021 15:48:07 +0300
rfc3339 2021-08-23T15:52:07+03:00
rfc3339x 2021-08-23T15:52:07.000+03:00

See Also