-
-
Save sunpietro/0ef51d1f2f8d140d822e0730053d5f0f to your computer and use it in GitHub Desktop.
Random date in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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