https://github.com/vicanso/nano-seconds
Get the nano seconds of current time
https://github.com/vicanso/nano-seconds
nano nanosecond nanoseconds
Last synced: 6 months ago
JSON representation
Get the nano seconds of current time
- Host: GitHub
- URL: https://github.com/vicanso/nano-seconds
- Owner: vicanso
- Created: 2017-03-07T12:53:29.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-09T13:39:27.000Z (over 7 years ago)
- Last Synced: 2025-03-25T21:35:55.923Z (7 months ago)
- Topics: nano, nanosecond, nanoseconds
- Language: JavaScript
- Homepage:
- Size: 39.1 KB
- Stars: 5
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
Awesome Lists containing this project
README
# nano-seconds
Get the nano seconds of now
[](https://travis-ci.org/vicanso/nano-seconds)
[](https://coveralls.io/r/vicanso/nano-seconds?branch=master)
[](https://www.npmjs.org/package/nano-seconds)
[](https://github.com/vicanso/nano-seconds)## Installation
```bash
$ npm install nano-seconds
```## API
### now
Get the nano seconds of current time, it will return [seconds, nanos]
```js
const nano = require('nano-seconds');
// [ 1488895112, 951851969 ]
console.info(nano.now());
```### toString
Format the nano seconds to string
- `ns` if not set the param, it will be `nano.now()`
```js
const nano = require('nano-seconds');
const ns = nano.now();
// [ 1488895353, 21164240 ]
console.info(ns);
// 1488895353021164240
console.info(nano.toString(ns));
// 1488895353025439741
console.info(nano.toString());
```### toISOString
Format the nano seconds to ISOString
- `ns` if not set the param, it will be `nano.now()`
```js
const nano = require('nano-seconds');
const ns = nano.now();
// 2017-06-22T14:37:42.506635539Z
console.info(nano.toISOString(ns));
// 2017-06-22T14:37:42.5069231Z
console.info(nano.toISOString());
```### fromISOString
Get the nano from ISOString
- `iosFormat` ISO Date String
```js
const nano = require('nano-seconds');
const arr = nano.fromISOString(str);
// [ 1505477440, 922020280 ]
console.info(arr);
```### difference
Get the difference of two nano seconds, ns2 - ns1
- `ns1` The start nano seconds
- `ns2` The end nano seconds, default is `nano.now()`
```js
const ns = nano.now();
setTimeout(() => {
const diff = nano.difference(ns);
// 102661874
console.info(diff);
}, 100);
```## License
MIT