Saturday, December 28, 2024
Google search engine
HomeLanguagesJavascriptMoment.js Business Plugin

Moment.js Business Plugin

Using the Moment.js Business plugin, you can use Moment for workweeks that follow the Western calendar: 7-day workweeks with Saturday and Sunday off. It provides a list of functions to identify weekdays, weekends, etc.

Write the below command in the terminal to install:

npm install moment-business

 

The following are some of the functions in this plugin:

  • weekDays
  • weekendDays
  • addWeekDays
  • subtractWeekDays
  • isWeekDay
  • isWeekendDay

The below examples will help to understand some of the methods of the Business Plugin.

Example 1:

Javascript




import moment from 'moment';
import business from "moment-business";
  
let today = moment();
let weekDay = business.isWeekDay(today);
console.log(today.format('dddd, DD-MM-yyyy'));
console.log(weekDay);


Output:

 

Example 2:

Javascript




import moment from 'moment';
import business from "moment-business";
  
let today = moment();
let next = business.addWeekDays(today, 10);
console.log(next.format('DD-MM-YYYY'));


Output:

 

Reference: https://momentjs.com/docs/#/plugins/moment-business/

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments