Skip to content

Instantly share code, notes, and snippets.

@AlexMcowkin
Created August 14, 2018 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexMcowkin/fb63da35f8db86550cc8e395a8a0dfe6 to your computer and use it in GitHub Desktop.
Save AlexMcowkin/fb63da35f8db86550cc8e395a8a0dfe6 to your computer and use it in GitHub Desktop.
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