Skip to content

Instantly share code, notes, and snippets.

@sunpietro
Forked from miguelmota/randomDate.js
Created April 7, 2019 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunpietro/0ef51d1f2f8d140d822e0730053d5f0f to your computer and use it in GitHub Desktop.
Save sunpietro/0ef51d1f2f8d140d822e0730053d5f0f to your computer and use it in GitHub Desktop.
Random date in JavaScript
function randomDate(start, end) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
console.log(randomDate(new Date(2012, 0, 1), new Date()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment