I'm looking to generate a random time. Right now I'm using chance.js to give me what is basically a random time but it's a bit broken. Here's my code:
$(".time").each(function(){
var hourSet = chance.hour(),
minuteSet = chance.minute(),
amPm = chance.ampm();
$(this).html(hourSet+':'+minuteSet+" "+amPm);
});
This spits out things like:
2:26 pm
8:1 pm
5:50 pm
The issue is that the minute generator sometimes generates single digit minutes like 8:1 pm
. I want it to generate 8:01 pm
if the minute is less than 10.
I was thinking of using moment.js to parse a timestamp that's randomly generated by chance.js but its complete overkill. It must be possible with what I have here.