Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including femtofiber with all npm packages installed. Try it out:

var femtofiber = require("femtofiber")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

femtofiber v0.0.1

A lightweight immutable date library.


femtofiber is immutable date library for JavaScript.

How to install

Without Node.js(for browsers)

Download a zip file from GitHub release page, and unzip it. Then you can see femtofiber.min.js in build directory. Copy femtofiber.min.js file to your project directory.

Import the file in your HTML as following:

<script src="femtofiber.min.js"></script>
  // Write your code here!

With Node.js(for server)

Run npm install.

npm install femtofiber --save 

And import it.

import { Femto, Duration } from 'femtofiber';

Basic Usage

Creating Femto

You can create a Femto object in several ways.

const femto1 = new Femto(2018, 6, 22);                  // from numbers
const femto2 = new Femto(2018, 6, 22, 21, 54, 31, 500); // from numbers with time
const femto3 = Femto.fromDate(new Date());              // from Date
const femto4 =;                             // from current date
const femto5 = Femto.fromEpochTime(1529590253022);      // from epoch time

A Femto object is immutable, so once created, its value does not change.


To get values, use properties.

const femto =;
console.log(femto.month); // January is 1, and December is 12

Formatting string

A Femto object also can output formatted string.

const femto =;
console.log(femto.toFormatString('YYYY/MM/DD'));   // "2018/06/22"
console.log(femto.toFormatString('HH:mm:ss:SSS')); // "18:23:27:758"


A Femto object has manipulating methods. You can manipulate date with Duration objects.

const tomorrow = Duration({days: 1}));
const yesterday = Duration({days: 1}));

To create a Duration object, pass values to Duration's constructor.

const duration = new Duration({
  days: 4,
  hours: 7,
  minutes: 13,
  seconds: 6,
  milliseconds: 219


You can also compare two Femtos.

const current = 1529665309363;
const femto1 = Femto.fromEpochTime(current);
const femto2 = Femto.fromEpochTime(current);

// These methods return boolean.
femto1.isSameOrAfter(femto2);, femto2);, femto2, {
  includesFrom: true,
  includesTo: true

API document

For more information, see API Document.


MIT License. See


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free