Last active
September 5, 2018 06:46
-
-
Save s4l4x/20698a978aeb09cae06fb451b2351fee to your computer and use it in GitHub Desktop.
[Date] Usage of the Date object
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
## randomDateInRange | |
randomDateInRange(start, end) { | |
return new Date( | |
start.getTime() + Math.random() * (end.getTime() - start.getTime()) | |
); | |
} | |
randomDateInRange(new Date(2018, 0, 1), new Date(2018, 3, 1)).toLocaleDateString(); | |
randomDateAfterDate(start, days) { | |
return new Date( | |
start.getTime() + (Math.random()*days*24*60*60*1000) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment