Created
August 14, 2018 07:10
-
-
Save AlexMcowkin/fb63da35f8db86550cc8e395a8a0dfe6 to your computer and use it in GitHub Desktop.
javascript: get random time between today and yesterday
This file contains 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
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> | |
<script src="https://momentjs.com/downloads/moment.js"></script> | |
<script> | |
$(document).ready(function() { | |
function getRandomMilisecond(min, max) | |
{ | |
var randomMinute = Math.floor(Math.random() * (max - min + 1)) + min; | |
return randomMinute * 60000; // 1 min = 60000 mls | |
} | |
var randomTime = new Date(Date.now() - getRandomMilisecond(5, 1440)); // 5 minutes; 1440 minutes - one day | |
var orderTime = moment(randomTime, "YYYYMMDD").fromNow(); | |
console.log(orderTime); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment