Date.create
Date.create($string|$map|$unixTime) -> Date
Description
Create a new date object, given an argument that can be one of the following:
- A date string (e.g. “2021-10-17”, “now”, “3 days ago”). See Date Strings.
- A map of date parts. See also toMap.
- A Unix timestamp (integer)
If given a map, it can have these fields:
year
month
day
hour
(defaults to 0)minute
(defaults to 0)second
(defaults to 0)
TypeStringsAs a shortcut, you can also create a Date object using TypeString syntax. (e.g.
date'2021-03-24'
, date'3 days ago'
)// 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 》