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

dt-formatter

v1.0.0

Published

A module designed to streamline the process of formatting Date() timestamps into human-readable date and time representations.

Downloads

11

Readme

DateTimeFormatter Module

The DateTimeFormatter module facilitates the formatting of date and time values in various formats. It provides methods to format dates, times, or both in customizable formats. This module is designed to be easy to use and flexible to accommodate different formatting needs.

The DateTimeFormatter module provides a convenient way to format dates and times in JavaScript/TypeScript applications. With its flexible API and customizable options, you can easily tailor the formatting to your specific needs. Whether you need to format dates, times, or both, this module has you covered.

Installation

To use the DateTimeFormatter module, you can install it via npm:

npm install dt-formatter

Usage

Importing

import { DateTimeFormatter } from 'dt-formatter';

Formatting Dates

You can format dates using the date method:

// Format the current date in the default format (DD/MM/YYYY)
const formattedDate = DateTimeFormatter.date(); // returns '5/3/2024'

You can also specify a custom date format:

// Format the current date in the custom format (YYYY-MM-DD) must be separated with a '-'
const formattedDate = DateTimeFormatter.date({ dateFormat: 'YYYY-MM-DD' }); // returns '2024/3/5'
const formattedDate = DateTimeFormatter.date({ dateFormat: 'YY-MM-DD', prefixZero: true }); // returns '24/03/05'

Formatting Times

Similarly, you can format times using the time method:

// Format the current time in the default format (HH:MM:SS)
const formattedTime = DateTimeFormatter.time(); // returns '12:30:45'

You can customize the time format as well:

// Format the current time in the custom format (HH:MM) must be separated with a ':'
const formattedTime = DateTimeFormatter.time({ timeFormat: 'HH:MM' }); // returns '12:30'
const formattedTime = DateTimeFormatter.time({ timeFormat: 'HH:MM:SS' }); // returns '12:30:45'

Formatting Date and Time Together

If you need to format both date and time together, you can use the format method:

// Format the current date and time in the default formats (DD/MM/YYYY HH:MM:SS)
const formattedDateTime = DateTimeFormatter.format(); // returns '5/3/2024 12:30:45'

You can specify custom formats for both date and time:

// Format the current date and time in custom formats (YYYY-MM-DD HH:MM)
const formattedDateTime = DateTimeFormatter.format({ dateFormat: 'YYYY-MM-DD', timeFormat: 'HH:MM' }); // returns '2024/5/3 12:30'

Additional Options

You can also provide additional options to control the formatting behavior:

  • timestamp: An optional timestamp to format. It can be a Date object, a string, or a number.
  • prefixZero: An optional boolean value to toggle the prefixing of '0' before a single digit in the formatted output.

Format String Table

| Format String | Output Description | |---------------|-------------------------------------------------| | YYYY | Full year (e.g., 2024) | | YY | Last two digits of the year (e.g., 24) | | MMMM | Full month name (e.g., January) | | MM | Month with leading zero (e.g., 01 for January) | | DD | Day of the month with leading zero (e.g., 01) | | hh | Hour with leading zero (e.g., 08 for 8 AM) | | mm | Minutes with leading zero (e.g., 05) | | ss | Seconds with leading zero (e.g., 03) |

Testing

This module includes unit tests to ensure its functionality.

npm test

License

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