UNPKG

821 BJavaScriptView Raw
1import { toDate } from "./toDate.mjs";
2
3/**
4 * @name getTime
5 * @category Timestamp Helpers
6 * @summary Get the milliseconds timestamp of the given date.
7 *
8 * @description
9 * Get the milliseconds timestamp of the given date.
10 *
11 * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
12 *
13 * @param date - The given date
14 *
15 * @returns The timestamp
16 *
17 * @example
18 * // Get the timestamp of 29 February 2012 11:45:05.123:
19 * const result = getTime(new Date(2012, 1, 29, 11, 45, 5, 123))
20 * //=> 1330515905123
21 */
22export function getTime(date) {
23 const _date = toDate(date);
24 const timestamp = _date.getTime();
25 return timestamp;
26}
27
28// Fallback for modularized imports:
29export default getTime;