消除我特牛
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1.4 KiB

birthday

// usage
chance.birthday()
chance.birthday({ string: true })
chance.birthday({ type: 'child' })

Generate a random birthday

chance.birthday();
=> Fri Aug 16 1985 00:00:00 GMT-0400 (EDT)

By default, returns an actual JavaScript Date object.

Optionally specify it be returned as a string.

chance.birthday({string: true});
=> '4/1/1968'

By default returns in MM/DD/YYYY format. Can specify DD/MM/YYYY as follows:

chance.birthday({string: true, american: false});
=> '28/6/1993'

For more complex date formats, use the Moment library.

Can also specify the type, same types as with age.

chance.birthday({type: 'child'});
=> Sat Sep 08 2001 00:00:00 GMT-0400 (EDT)

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:

var year = chance.year({ min: 1450, max: 1500 });
chance.birthday({ year: year });
=> Wed Aug 27 1484 11:24:14 GMT-0400 (EDT)

// Could be simplified down to one line
chance.birthday({ year: chance.year({ min: 1450, max: 1500 }) });
=> Fri Nov 26 1469 09:17:13 GMT-0500 (EST)