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

Date.create

Date.create($string|$map|$unixTime) -> Date

Description

Create a new date object, given an argument that can be one of the following:

If given a map, it can have these fields:

// Formatted date string
$date = Date.create('2021-10-17')
//= 《 Date 2021-10-17 00:00:00 +0000 》

// TypeString syntax
$date = date'2021-10-17'
//= 《 Date 2021-10-17 00:00:00 +0000 》

// Relative date string
$date = Date.create('3 days ago')
//= 《 Date 2021-07-29 15:42:01 +0000 》

// Unix time
$laterUnix = $date.unixTime() + 3600  // + 1 hour
$date = Date.create($laterUnix)
//= 《 Date 2021-07-29 16:42:01 +0000 》
//                     ^^

// Map
$dateMap = { year: 2021, month: 10, day: 27 }
$date = Date.create($dateMap)
//= 《 Date 2021-10-27 00:00:00 +0000 》

See Also