date
// usage
randBox.date()
randBox.date({string: true})
randBox.date({string: true, american: false})
randBox.date({year: 1983})
Generate a random date
randBox.date();
=> Sat Apr 09 2072 00:00:00 GMT-0400 (EDT)
By default, returns an actual Dateย object
Can optionally specify that a date be returned as a string
randBox.date({string: true});
=> "5/27/2078"
This will return a date string of the format MM/DD/YYYY.
Now of course MM/DD/YYYY is the โAmericanโ date method, but itโs the default because there isnโt much support for internationalization here yet. Further, itโs the format used by Facebookย and other services for birthdays and other non-Date object dates.
However, we support returning dates in DD/MM/YYYY format as well when requesting
a date by a string and passing american: false
.
randBox.date({string: true, american: false});
=> "13/2/2017"
If you want richer control over date format, strongly suggest using the Momentย library. Our formatting is very minimalist, and itโs out of our core competency to offer dates in a myriad of formats.
Can optionally specify defaults for any of day, month, or year.
randBox.date({year: 1983});
=> Wed May 04 1983 00:00:00 GMT-0400 (EDT)
randBox.date({month: 0});
=> Tue Jan 18 2084 00:00:00 GMT-0500 (EST)
randBox.date({day: 21});
=> Sun Oct 21 2103 00:00:00 GMT-0400 (EDT)
A random date is generated, but the default you specify is kept constant.
Note, month is 0-indexed. This is a carryover from the core JavaScript Dateย object which we use internally to generate the date.