项目作者: vicanso

项目描述 :
Get the nano seconds of current time
高级语言: JavaScript
项目地址: git://github.com/vicanso/nano-seconds.git
创建时间: 2017-03-07T12:53:29Z
项目社区:https://github.com/vicanso/nano-seconds

开源协议:

下载


nano-seconds

Get the nano seconds of now

Build Status
Coverage Status
npm
Github Releases

Installation

  1. $ npm install nano-seconds

API

now

Get the nano seconds of current time, it will return [seconds, nanos]

  1. const nano = require('nano-seconds');
  2. // [ 1488895112, 951851969 ]
  3. console.info(nano.now());

toString

Format the nano seconds to string

  • ns if not set the param, it will be nano.now()
  1. const nano = require('nano-seconds');
  2. const ns = nano.now();
  3. // [ 1488895353, 21164240 ]
  4. console.info(ns);
  5. // 1488895353021164240
  6. console.info(nano.toString(ns));
  7. // 1488895353025439741
  8. console.info(nano.toString());

toISOString

Format the nano seconds to ISOString

  • ns if not set the param, it will be nano.now()
  1. const nano = require('nano-seconds');
  2. const ns = nano.now();
  3. // 2017-06-22T14:37:42.506635539Z
  4. console.info(nano.toISOString(ns));
  5. // 2017-06-22T14:37:42.5069231Z
  6. console.info(nano.toISOString());

fromISOString

Get the nano from ISOString

  • iosFormat ISO Date String
  1. const nano = require('nano-seconds');
  2. const arr = nano.fromISOString(str);
  3. // [ 1505477440, 922020280 ]
  4. 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()

  1. const ns = nano.now();
  2. setTimeout(() => {
  3. const diff = nano.difference(ns);
  4. // 102661874
  5. console.info(diff);
  6. }, 100);

License

MIT