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

Elabid Asmaa @elabid_asmaa

About: Asmaa Elabid , a Developer dedicated to creating scalable, user-focused web applications. Focused on solving problems and delivering seamless user experiences.

Location:
Morocco
Joined:
Jul 15, 2024

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

Publish Date: Jan 10
2 0

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. 🌐

Comments 0 total

    Add comment