MomentJS - Hour


Advertisements

This method will get/set the hour. It takes input from 0-23, if greater than the range provided, it will add to the day.

Syntax

moment().hour(Number);
moment().hour();
moment().hours(Number);
moment().hours();

Example

var m = moment().hour(); // gets the current hour
var d = moment().hour(8); // sets the hour as shown below

Output

hour
momentjs_getter_setter.htm
Advertisements