Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
javascript: get random time between today and yesterday
<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
You can’t perform that action at this time.