UNPKG

761 BJavaScriptView Raw
1"use strict";
2exports.getUnixTime = getUnixTime;
3var _index = require("./toDate.js");
4
5/**
6 * @name getUnixTime
7 * @category Timestamp Helpers
8 * @summary Get the seconds timestamp of the given date.
9 *
10 * @description
11 * Get the seconds timestamp of the given date.
12 *
13 * @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).
14 *
15 * @param date - The given date
16 *
17 * @returns The timestamp
18 *
19 * @example
20 * // Get the timestamp of 29 February 2012 11:45:05 CET:
21 * const result = getUnixTime(new Date(2012, 1, 29, 11, 45, 5))
22 * //=> 1330512305
23 */
24function getUnixTime(date) {
25 return Math.trunc(+(0, _index.toDate)(date) / 1000);
26}