- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
Using Day.js Plugins in Node.js Applications
Discover essential plugins and best practices for efficient date handling.
Using Day.js Plugins to Extend Date Functionality in Node.js

Working with dates in JavaScript has always been a bit tricky. While the native Date object gives us basic functionality, it often falls short when we need more advanced features. That’s where Day.js comes in – a lightweight alternative to Moment.js that’s perfect for modern applications. Today, let’s explore how to supercharge Day.js with plugins in your Node.js projects.
Getting Started with Day.js Plugins
First things first, let’s set up our project. If you haven’t already, install Day.js:
npm install dayjsThe beauty of Day.js lies in its plugin system. Instead of loading everything at once, you only import the functionality you need. This keeps your application lightweight and performant.

Essential Plugins for Every Project
Let’s dive into some of the most useful plugins you’ll want to consider:
1. RelativeTime Plugin
The RelativeTime plugin lets you display dates in a human-friendly format. Perfect for social media apps or any interface where you want to show “2 hours ago” instead of the full timestamp.
const dayjs = require('dayjs')const relativeTime = require('dayjs/plugin/relativeTime')dayjs.extend(relativeTime)
console.log(dayjs().from(dayjs('2023-01-01'))) // displays "1 year ago"2. CustomParseFormat Plugin
When you need to work with custom date formats, this plugin is invaluable:
const customParseFormat = require('dayjs/plugin/customParseFormat')dayjs.extend(customParseFormat)
const date = dayjs('2024-03-15 16:30', 'YYYY-MM-DD HH:mm')
3. Duration Plugin
Calculate and manipulate durations with ease:
const duration = require('dayjs/plugin/duration')dayjs.extend(duration)
const duration = dayjs.duration({ hours: 2, minutes: 30})console.log(duration.humanize()) // displays "2.5 hours"Pro Tips for Plugin Usage
-
Chain Multiple Plugins: Plugins can work together seamlessly. For example, combine UTC and Timezone plugins for robust international date handling.
-
Plugin Loading Order: Some plugins depend on others. Always check the documentation for dependencies and load them in the correct order.
-
Performance Considerations: Only load the plugins you need. Each plugin adds to your bundle size, so be mindful of what you import.
Conclusion
Day.js plugins provide a flexible and powerful way to handle dates in your Node.js applications. By choosing the right combination of plugins, you can create a custom date manipulation toolkit that’s perfect for your specific needs, all while keeping your application lightweight and maintainable.

สร้างเว็บไซต์ 1 เว็บ ต้องใช้งบเท่าไหร่? เจาะลึกทุกองค์ประกอบ website development cost อยากสร้างเว็บไซต์แต่ไม่มั่นใจในเรื่องของงบประมาณ อ่านสรุปเจาะลึกตั้งแต่ดีไซน์, ฟังก์ชัน และการดูแล พร้อมตัวอย่างงบจริงจาก Till it’s done ที่แผนชัด งบไม่บานปลายแน่นอน
Next.js สอน 14 ขั้นตอนเบื้องต้น: สร้างโปรเจกต์แรกใน 30 นาที เริ่มต้นกับ Next.js ใน 14 ขั้นตอนเพียงแค่ 30 นาที พร้อม SSR/SSG และ API Routes ด้วยตัวอย่างโค้ดง่าย ๆ อ่านต่อเพื่อสร้างโปรเจ็กต์แรกได้ทันทีที่นี่
วิธีสมัคร Apple Developer Account เพื่อนำแอปขึ้น App Store ทีละขั้นตอน อยากปล่อยแอปบน App Store ระดับโลก มาอ่านคู่มือสมัคร Apple Developer Account พร้อมเคล็ดลับ TestFlight และวิธีอัปโหลดที่ง่ายในบทความเดียวนี้ได้เลย
TypeScript Interface คืออะไร? อธิบายพร้อมวิธีใช้และข้อแตกต่างจาก Type เรียนรู้วิธีใช้ TypeScript Interface เพื่อสร้างโครงสร้างข้อมูลที่ปลอดภัยและเข้าใจง่าย พร้อมเปรียบเทียบข้อดีข้อแตกต่างกับ Type ที่คุณต้องรู้ ถูกรวมเอาไว้ในบทความนี้แล้ว
Material-UI (MUI) คืออะไร อยากสร้าง UI สวยงามและเป็นมืออาชีพในเวลาอันรวดเร็วใช่ไหม มาทำความรู้จักกับ Material-UI (MUI) ที่ช่วยให้คุณพัฒนาแอปพลิเคชันบน React ได้ง่ายและดูดีในทุกอุปกรณ์
เปรียบเทียบ 3 วิธีติดตั้ง install node js บน Ubuntu: NVM vs NodeSource vs Official Repo แบบไหนดีที่สุด? เรียนรู้วิธีติดตั้ง Node.js บน Ubuntu ด้วย NVM, NodeSource หรือ Official Repo เลือกวิธีที่เหมาะกับความต้องการของคุณ พร้อมเปรียบเทียบ เพื่อการพัฒนาที่มีประสิทธิภาพ! พูดคุยกับซีอีโอ
We'll be right here with you every step of the way.
We'll be here, prepared to commence this promising collaboration.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.