Coder Social home page Coder Social logo

quartzite's Introduction

Quartzite

Lightweight relative date/time formatter without external dependencies.
The formatter offers three styles - short, medium and long.

Styles

Short Medium Long
now Just now Today, 18:00
25s 25 seconds ago Today, 18:00
30m 30 minutes ago Today, 17:30
18h Today Today 00:00
2d Yesterday Yesterday, 07:00
5d November 7 Thursday, November 7th
Oct 8, 2018 October 8, 2018 October 8th, 2018
In 25s In 25 seconds Today, 10:00
In 30m In 30 minutes Today, 10:30
In 18h Tomorrow Tomorrow, 04:00
In 2d Thursday Thursday, 10:00
In 5d November 17 Sunday, November 17th
Dec 16, 2020 December 16, 2020 December 16th, 2020

Installation

Using npm

$ npm install quartzite

Using cdn

<script src="https://unpkg.com/quartzite/dist/quartzite.js"></script>

Example

Importing as ES6 module

import * as quartzite from 'quartzite';

or using CommonJS

const quartzite = require('quartzite');

Create date in the past

const date = new Date();
const yesterday = quartzite.dateByAdding('hours', date, -25);

Create date in the future

const date = new Date();
const someday = quartzite.dateByAdding('days', date, 5);

Format date using medium style

console.log(quartzite.dateString(yesterday)); // Medium is the default option
console.log(quartzite.dateString(someday, 'medium'));

Format date using short style

console.log(quartzite.dateString(someday, 'short'));

Format date using long style

console.log(quartzite.dateString(someday, 'long'));

License

Licensed under the MIT License.

quartzite's People

Contributors

robbdimitrov avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

mi1121

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.