# unix-timestamp

> Tiny library to create and manipulate Unix timestamps

Latest version **1.1.0** (published 2024-08-11) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install unix-timestamp
pnpm add unix-timestamp
yarn add unix-timestamp
bun add unix-timestamp
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2024-08-11 |
| First published | 2014-02-15 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Simon Goumaz |
| Maintainers | sgoumaz |
| Keywords | timestamp, unix, time |

## Links

- npm: https://www.npmjs.com/package/unix-timestamp
- Repository: https://github.com/attentif/unix-timestamp-js
- Homepage: https://github.com/attentif/unix-timestamp-js#readme
- Issues: http://github.com/attentif/unix-timestamp/issues
- npm.io page: https://npm.io/package/unix-timestamp

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2024-08-11
- 1.0.4 — 2023-12-04
- 1.0.3 — 2023-02-13
- 1.0.2 — 2022-04-20
- 1.0.1 — 2022-04-20
- 1.0.0 — 2022-04-13
- 0.2.0 — 2015-02-19
- 0.1.2 — 2014-02-24
- 0.1.1 — 2014-02-15
- 0.1.0 — 2014-02-15

## README

# unix-timestamp

[![CI](https://github.com/attentif/unix-timestamp-js/workflows/CI/badge.svg)](https://github.com/attentif/unix-timestamp-js/actions/workflows/ci.yml) [![npm](https://img.shields.io/npm/v/unix-timestamp)](https://www.npmjs.com/package/unix-timestamp)

Tiny library to create and manipulate Unix timestamps in Javascript. (A Unix timestamp is the number of seconds elapsed since Unix epoch time, i.e. January 1 1970 00:00 UTC.)


## Usage

```sh
npm install unix-timestamp
```

Then:
```javascript
const timestamp = require('unix-timestamp');
```

### Methods

- `.now([offset])` gives the current time, optionally applying an offset (see below)
- `.fromDate(dateOrString)` gives the time from a Javascript Date object or an ISO 8601 date string
- `.toDate(time)` correspondingly gives the date from a timestamp
- `.add(time, offset)` applies an offset to the given time
- `.duration(offset)` gives the offset timestamp for the given offset string

An offset can be either a number (unit: seconds) or a string with format `[+|-] [{years}y] [{months}M] [{weeks}w] [{days}d] [{hours}h] [{minutes}m] [{seconds}s] [{milliseconds}ms]` (for example `-30s`).

The actual values (in seconds) used for each unit of time in an offset string are exposed by properties `.Millisecond`, `.Second`, `.Minute`, `.Hour`, `.Day`, `.Week`, `.Month` (i.e. mean Gregorian month) and `.Year`.

### About rounding

By default timestamps include decimals (fractions of a second). You can set the lib to round all returned timestamps to the second with `timestamp.round = true`.


## Contributing

`npm test` runs the [tests](./test) with [Mocha](https://mochajs.org/).

`npm run test-cover` runs the tests and outputs coverage stats with [Istanbul](https://istanbul.js.org/).

`npm run license` updates license information with [source-licenser](https://github.com/pryv/source-licenser).

The code follows the [Semi-Standard](https://github.com/standard/semistandard) style.


## License

[BSD-3-Clause](https://github.com/attentif/unix-timestamp-js/blob/master/LICENSE)

---
_Source: https://npm.io/package/unix-timestamp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
