Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created June 29, 2017 18:33
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save indexzero/6261ad9292c78cf3c5aa69265e2422bf to your computer and use it in GitHub Desktop.
Save indexzero/6261ad9292c78cf3c5aa69265e2422bf to your computer and use it in GitHub Desktop.
Generate a 24 hour range of 30-minute time intervals that are i18n compatible
let items = [];
for (var hour = 0; hour < 24; hour++) {
items.push([hour, 0]);
items.push([hour, 30]);
}
const date = new Date();
const formatter = new Intl.DateTimeFormat('en-US', {
hour: 'numeric',
minute: 'numeric',
hour12: false
});
const range = items.map(time => {
const [hour, minute] = time;
date.setHours(hour);
date.setMinutes(minute);
return formatter.format(date);
});
console.dir(range);
@RaviTr-web
Copy link

Awesome, very useful

@outOFFspace
Copy link

outOFFspace commented Aug 20, 2023

mmm image

Use { hourCycle: 'h23' } instead of { hour12: false }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment