javascript - generate date range base on integers -


i have array [0,1,2,3 .. 23] , means hour in day. how use moment js convert them 12 hour date range?

my desire output is

['12am-1am','1am-2am','2am-3am' .. 11pm-12am] 

my attempt failed coz thought don't need moment https://jsfiddle.net/s4l7hj1a

you don't need moment.js

var getformattedhour = function(hour) {    return (hour % 12 ? hour % 12 : 12) + ':00 ' + ((hour < 12) || (hour >= 24) ? 'am' : 'pm');  }    var gethourrange = function(hour) {      return getformattedhour(hour) + ' - ' + getformattedhour(hour + 1);  }    var hours = [];  for(var hour = 0; hour < 24; hour++) {    hours.push(hour);  }    hours.map(function(hour) {    console.log(gethourrange(hour));  });


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -