npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

i18time

v1.0.3

Published

A javascript package for working with Date objects

Downloads

8

Readme

i18time

A javascript package for working with Date objects

Installation

You can install this package via npm by running the following command:

npm install i18time

Or if you are using yarn, run:

yarn add i18time

Usage

First, import the library into your project:

const i18Time = require("i18time");

import * as i18Time from "i18time"; // ES6 modules

Then, you can use the package:

// Import the i18time package
const i18Time = require("i18time");

// Alternatively, if you are using ES6 modules
import * as i18Time from "i18time";

// Get the current timestamp in milliseconds
const currentTimestampInMillis = i18Time.getTimestampInMilliseconds();
console.log("Current Timestamp in Milliseconds:", currentTimestampInMillis);

// Get the current UNIX timestamp (in seconds)
const currentUnixTimestamp = i18Time.getCurrentUnixTimesamp();
console.log("Current UNIX Timestamp:", currentUnixTimestamp);

// Get the current UNIX timestamp as a string
const currentUnixTimestampString = i18Time.getCurrentUnixTimesampString();
console.log("Current UNIX Timestamp (String):", currentUnixTimestampString);

// Convert timestamp to Date object
const timestamp = 1718138899408; // Example timestamp in milliseconds
const dateFromTimestamp = i18Time.timestampToDate(timestamp);
console.log("Date from Timestamp:", dateFromTimestamp);

// Format a Date object into a string
const formattedDate = i18Time.formatDate(
  dateFromTimestamp,
  "YYYY-MM-DD HH:mm:ss"
);
console.log("Formatted Date:", formattedDate);

// Get the current time in a specific timezone
const currentTimeInTimezone = i18Time.getCurrentTimeInTimezone(7); // Example: UTC+7
console.log("Current Time in Timezone:", currentTimeInTimezone);

// Get the current UTC time
const currentUTCTime = i18Time.getUTCTime();
console.log("Current UTC Time:", currentUTCTime);

// Calculate the difference between two Date objects
const date1 = new Date("2024-06-12T08:00:00");
const date2 = new Date("2024-06-13T08:00:00");
const differenceInMilliseconds = i18Time.differenceInMilliseconds(date1, date2);
console.log("Difference in Milliseconds:", differenceInMilliseconds);

const differenceInSeconds = i18Time.differenceInSeconds(date1, date2);
console.log("Difference in Seconds:", differenceInSeconds);

const differenceInMinutes = i18Time.differenceInMinutes(date1, date2);
console.log("Difference in Minutes:", differenceInMinutes);

const differenceInHours = i18Time.differenceInHours(date1, date2);
console.log("Difference in Hours:", differenceInHours);

const differenceInDays = i18Time.differenceInDays(date1, date2);
console.log("Difference in Days:", differenceInDays);

Features

  • Date Formatting: Provide functions to format Date objects into strings according to various formats commonly used in different locales.

  • Timezone Support: Offer functionality to work with different time zones, allowing users to convert and display times in their local time.

  • Timestamp Conversion: Enable conversion between UNIX timestamps (in seconds or milliseconds) and Date objects.

  • Date Comparison: Implement functions to calculate the difference between two Date objects in milliseconds, seconds, minutes, hours, or days.

  • Localization: Support for localization, allowing users to display dates and times in their preferred language and format.

  • Customization: Allow users to specify custom date and time formats according to their requirements.

Note

This package is in the testing