Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active December 21, 2022 16:27
Show Gist options
  • Save miguelmota/5b67e03845d840c949c4 to your computer and use it in GitHub Desktop.
Save miguelmota/5b67e03845d840c949c4 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()))
@Heunsig
Copy link

Heunsig commented Nov 8, 2022

Thank you!

@DidarHalla
Copy link

Good job, but i don't understand, how it's work.... Please explain)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment