@tdb/util
Version:
Shared helpers and utilities.
25 lines (22 loc) • 461 B
text/typescript
import { moment } from '../../libs';
/**
* Retrieves a unix timestamp.
*
* See:
* https://coderwall.com/p/rbfl6g/how-to-get-the-correct-unix-timestamp-from-any-date-in-javascript
*
*/
export function toTimestamp(date?: Date) {
return moment(date || new Date())
.utc()
.unix();
}
/**
* Converts a timestamp into a Date.
*/
export function fromTimestamp(timestamp: number) {
return moment
.unix(timestamp)
.utc()
.toDate();
}