format-date-time

Small date and time formater. Format by user mask or with default format

Usage no npm install needed!

<script type="module">
  import formatDateTime from 'https://cdn.skypack.dev/format-date-time';
</script>

README

format-date-time

Build Status Coverage Status

Date time formatter

Lightweight date time formatter for node and browser.

Getting started

Browser usage see in examples directory.

Node usage:

npm i format-date-time --save
import DateTimeFormat from 'format-date-time'

const defaultFormatter = new DateTimeFormat();

console.log(defaultFormatter.parse()); // return current date/time in default format
console.log(defaultFormatter.parse(new Date ("2017-10-02T05:05:05.985Z"), 'HH:mm:ss'));
console.log(defaultFormatter.parse("2017-10-02T08:18:31.985Z", 'HH:mm:ss (year: YYYY)')); // time string instead of Date object
console.log(defaultFormatter.now('HH:mm:ss')); // current time in specified format
console.log(defaultFormatter.now('HH:mm:ss (DD-MM-YYYY)'));

or set format mask in the constructor:

const formatter = new DateTimeFormat('HH:mm (YYYY-MM-DD)');
console.log(formatter.now()); // current date/time in format settled in constructor
console.log(formatter.parse(new Date ("2017-10-02T05:05:05.985Z")));

Running the tests

Run test:

npm run test

Run test on Windows machine

npm run testWin

Versioning

We use SemVer for versioning.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details