util.timestamp
v0.0.44
Published
Generates a string timestamp
Downloads
14
Readme
util.timestamp
Generates a string timestamp
This module is a thin wrapper on the strftime module to create a simple string timestamp with a consistent format. It uses the format rule:
%Y%m%d%H%M%S%L
This results in a 17 byte string representing the current timestamp. e.g.
20170126075705148
Installation
This module uses yarn to manage dependencies and run scripts for development.
To install as a global package:
$ yarn global add util.timestamp
To install as a development dependency with cli:
$ yarn add --dev util.timestamp
To build the app and run all tests:
$ yarn run all
Usage
There are two ways to use this package:
- Command line
- Function call
Command line
The timestamp can be generated from the command line using:
timestamp
This will return the default format above. This could be used in scripting.
Function call
The default JavaScript call will just return the timestamp format above as a string:
const timestamp = require('util.timestamp');
console.log(timestamp());
The function also has an option to set a format that is acceptable to the strftime library:
const timestamp = require('util.timestamp');
console.log(timestamp({
dateFormat: '%B %d, %Y %H:%M:%S'
}));
// returns the string: 'April 28, 2011 18:21:08'