1 | # birthday
|
2 |
|
3 | ```js
|
4 | // usage
|
5 | chance.birthday()
|
6 | chance.birthday({ string: true })
|
7 | chance.birthday({ type: 'child' })
|
8 | ```
|
9 |
|
10 | Generate a random birthday
|
11 |
|
12 | ```js
|
13 | chance.birthday();
|
14 | => Fri Aug 16 1985 00:00:00 GMT-0400 (EDT)
|
15 | ```
|
16 |
|
17 | By default, returns an actual JavaScript [Date][Date] object.
|
18 |
|
19 | Optionally specify it be returned as a string.
|
20 |
|
21 | ```js
|
22 | chance.birthday({string: true});
|
23 | => '4/1/1968'
|
24 | ```
|
25 |
|
26 | By default returns in MM/DD/YYYY format. Can specify DD/MM/YYYY as follows:
|
27 |
|
28 | ```js
|
29 | chance.birthday({string: true, american: false});
|
30 | => '28/6/1993'
|
31 | ```
|
32 |
|
33 | For more complex date formats, use the [Moment][Moment] library.
|
34 |
|
35 | Can also specify the type, same types as with [age](#age).
|
36 |
|
37 | ```js
|
38 | chance.birthday({type: 'child'});
|
39 | => Sat Sep 08 2001 00:00:00 GMT-0400 (EDT)
|
40 | ```
|
41 |
|
42 | You can also compose with `chance.year` for interesting combinations. For example, let's say we want to get the birthdays of some renaissance artists (born between 1450 and 1500). We can generate a year and then get a birthday from that year:
|
43 |
|
44 | ```js
|
45 | var year = chance.year({ min: 1450, max: 1500 });
|
46 | chance.birthday({ year: year });
|
47 | => Wed Aug 27 1484 11:24:14 GMT-0400 (EDT)
|
48 |
|
49 | // Could be simplified down to one line
|
50 | chance.birthday({ year: chance.year({ min: 1450, max: 1500 }) });
|
51 | => Fri Nov 26 1469 09:17:13 GMT-0500 (EST)
|
52 | ```
|
53 |
|
54 | [Date]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
|
55 | [Moment]: http://momentjs.com
|