programming-examples/js/Date/Write a JavaScript function to get 12-hour format of an hour with leading zeros..js
2019-11-15 12:59:38 +01:00

10 lines
271 B
JavaScript

function hours_with_zeroes(dt)
{
return ((dt.getHours() % 12 || 12) < 10 ? '0' : '') + (dt.getHours() % 12 || 12);
}
dt = new Date();
console.log(hours_with_zeroes(dt));
dt = new Date(1989, 10, 1);
console.log(hours_with_zeroes(dt));