UNPKG

627 BJavaScriptView Raw
1import { toDate } from "./toDate.js";
2
3/**
4 * The {@link getMonth} function options.
5 */
6
7/**
8 * @name getMonth
9 * @category Month Helpers
10 * @summary Get the month of the given date.
11 *
12 * @description
13 * Get the month of the given date.
14 *
15 * @param date - The given date
16 * @param options - An object with options
17 *
18 * @returns The month index (0-11)
19 *
20 * @example
21 * // Which month is 29 February 2012?
22 * const result = getMonth(new Date(2012, 1, 29))
23 * //=> 1
24 */
25export function getMonth(date, options) {
26 return toDate(date, options?.in).getMonth();
27}
28
29// Fallback for modularized imports:
30export default getMonth;