programming-examples/js/Date/Write a JavaScript function to get the quarter (1 to 4) of the year..js
2019-11-15 12:59:38 +01:00

10 lines
308 B
JavaScript

function quarter_of_the_year(date)
{
var month = date.getMonth() + 1;
return (Math.ceil(month / 3));
}
console.log(quarter_of_the_year(new Date()));
console.log(quarter_of_the_year(new Date(2015, 1, 21)));
console.log(quarter_of_the_year(new Date(2015, 10, 18)));