DEV Community

Cover image for Introducing date-formatter-i18n: Simplify i18n for Dates in JavaScript
Elabid Asmaa
Elabid Asmaa

Posted on

2 1

Introducing date-formatter-i18n: Simplify i18n for Dates in JavaScript

As developers, we often deal with dates in our applications, and it’s never as simple as it seems. What format should we use? How do we account for user locales? What about relative time like "3 days ago"?

Introducing date-formatter-i18n, a lightweight NPM package that makes date formatting and localization effortless.

Here’s what it offers:


Features

  • 📅 Date Formatting: Convert raw dates into readable formats across locales.

  • ⏳ Relative Time: Display times like "2 days ago" or "in 1 hour" dynamically.

  • 🌍 i18n Support: Easily switch between languages like English, French, and German.


Why Use This Library?

Existing solutions can be heavy, complex, or lack proper i18n support. date-formatter-localized focuses on simplicity, making it perfect for multilingual apps.

Here’s an example:

import DateFormatter from 'date-formatter-i18n';

// Create an instance of DateFormatter
const dateFormatter = new DateFormatter('en');

const formattedDate = dateFormatter.format('2023-12-25'); 
// Output: "December 25, 2023"

// Relative time
const pastDate = new Date(Date.now() - 3 * 24 * 60 * 60 * 1000);
console.log(dateFormatter.formatRelative(pastDate));
// Output: 3 days ago

Enter fullscreen mode Exit fullscreen mode

Get Started

To install:

npm install date-formatter-localized


Contribute

Want to add more locales or features? Head over to the GitHub repo and contribute!

If you find it helpful, please star ⭐ the repository to show your support!

Let’s make date formatting smarter, simpler, and more global. 🌐

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay