UNPKG

590 BJavaScriptView Raw
1import { toDate } from "./toDate.js";
2
3/**
4 * @name getUnixTime
5 * @category Timestamp Helpers
6 * @summary Get the seconds timestamp of the given date.
7 *
8 * @description
9 * Get the seconds timestamp of the given date.
10 *
11 * @param date - The given date
12 *
13 * @returns The timestamp
14 *
15 * @example
16 * // Get the timestamp of 29 February 2012 11:45:05 CET:
17 * const result = getUnixTime(new Date(2012, 1, 29, 11, 45, 5))
18 * //=> 1330512305
19 */
20export function getUnixTime(date) {
21 return Math.trunc(+toDate(date) / 1000);
22}
23
24// Fallback for modularized imports:
25export default getUnixTime;