项目作者: sh4hids

项目描述 :
Bangla calendar utils
高级语言: JavaScript
项目地址: git://github.com/sh4hids/bangla-calendar.git
创建时间: 2019-08-16T10:28:31Z
项目社区:https://github.com/sh4hids/bangla-calendar

开源协议:MIT License

下载


📅 bangla-calendar Stars · License · GitHub issues

A small JavaScript library to convert any valid JavaScript date to Bangla date.

Install

  1. $ npm i bangla-calendar

Usage

  1. const {
  2. getDate,
  3. getDay,
  4. getWeekDay,
  5. getMonth,
  6. getYear,
  7. } = require('bangla-calendar');

or

  1. import {
  2. getDate,
  3. getDay,
  4. getMonth,
  5. getWeekDay,
  6. getYear,
  7. } from 'bangla-calendar';
  1. const date1 = new Date('August 16 2019 06:22:03');
  2. getDate(date1); //output: শুক্রবার, ১ ভাদ্র, ১৪২৬
  3. getDate(date1, { format: 'DD/MM/YYYY' }); //output: ০১/০৫/১৪২৬

Methods

getDate(date, {})

This method returns full Bangla date for a given date.

Examples

  1. const date1 = new Date('August 16 2019 06:22:03');
  2. getDate(date1); //output: শুক্রবার, ১ ভাদ্র, ১৪২৬
  3. getDate(date1, { format: 'DD/MM/YY', calculationMethod: 'BD' }); //output: ০১/০৫/২৬
  4. getDate(date1, { format: 'DD/MM/YYYY', calculationMethod: 'BD' }); //output: ০১/০৫/১৪২৬
  5. getDate(date1, { format: 'DD/MM/YYYYb', calculationMethod: 'BD' }); //output: ০১/০৫/১৪২৬ (বঙ্গাব্দ)
  6. getDate(date1, { format: 'D MMMM, YYYY', calculationMethod: 'BD' }); //output: ১ ভাদ্র, ১৪২৬
  7. getDate(date1, { format: 'D MMMM, YYYYb', calculationMethod: 'BD' }); //output: ১ ভাদ্র, ১৪২৬ (বঙ্গাব্দ)

Parameters

Parameter Type Example
date JavaScript date new Date('August 16 2019 06:22:03')
options object { format: 'D MMMM, YYYY', calculationMethod: 'BD' }

getDay(date, {})

This method returns the day of the Bangla month of the given date.

Examples

  1. const date1 = new Date('August 16 2019 06:22:03');
  2. getDay(date1); //output: ১
  3. getDay(date1, { format: 'DD', calculationMethod: 'BD' }); //output: ০১
  4. getDay(date1, { format: 'D', calculationMethod: 'BD' }); //output: ১

Parameters

Parameter Type Example
date JavaScript date new Date('August 16 2019 06:22:03')
options object { format: 'D', calculationMethod: 'BD' }

getWeekDay(date, {})

This method returns the day of the Bangla week of the given date.

Examples

  1. const date1 = new Date('August 16 2019 06:22:03');
  2. getWeekDay(date1); //output: শুক্রবার
  3. getWeekDay(date1, { format: 'eeee', calculationMethod: 'BD' }); //output: শুক্রবার
  4. getWeekDay(date1, { format: 'eee', calculationMethod: 'BD' }); //output: শুক্র

Parameters

Parameter Type Example
date JavaScript date new Date('August 16 2019 06:22:03')
options object { format: 'eeee', calculationMethod: 'BD' }

getMonth(date, {})

This method returns the Bangla month of a given date.

Examples

  1. const date1 = new Date('August 16 2019 06:22:03');
  2. getMonth(date1); //output: ভাদ্র
  3. getMonth(date1, { format: 'M', calculationMethod: 'BD' }); //output: ১
  4. getMonth(date1, { format: 'MM', calculationMethod: 'BD' }); //output: ০১
  5. getMonth(date1, { format: 'MMMM', calculationMethod: 'BD' }); //output: ভাদ্র

Parameters

Parameter Type Example
date JavaScript date new Date('August 16 2019 06:22:03')
options object { format: 'MMMM', calculationMethod: 'BD' }

getYear(date, {})

This method returns the Bangla year of a given date.

Examples

  1. const date1 = new Date('August 16 2019 06:22:03');
  2. getYear(date1); //output: ১৪২৬
  3. getYear(date1, { format: 'YY', calculationMethod: 'BD' }); //output: ২৬
  4. getYear(date1, { format: 'YYYY', calculationMethod: 'BD' }); //output: ১৪২৬
  5. getYear(date1, { format: 'YYYYb', calculationMethod: 'BD' }); //output: ১৪২৬ (বঙ্গাব্দ)

Parameters

Parameter Type Example
date JavaScript date new Date('August 16 2019 06:22:03')
options object { format: 'YYYY', calculationMethod: 'BD' }

Options

calculationMethod (string)

Country Token
Bangladesh BD
India IN

format (string)

Unit Token Result examples
Day D ১, ২, ৩, ৪, …, ৩০, ৩১
DD ০১, ০২, ০৩, ০৪, …, ৩০,
Weekday eee শুক্র, শনি, রবি, …, বৃহস্পতি
eeee শুক্রবার, শনিবার, রবিবার, …, বৃহস্পতিবার
Month M ১, ২, ৩, ৪, …, ১১, ১২
MM ০১, ০২, ০৩, ০৪, …, ১১, ১২
MMMM বৈশাখ, জ্যৈষ্ঠ, আষাঢ়, শ্রাবণ, …, ফাল্গুন, চৈত্র
Year YY ২০, ২১, ২২, …, ২৫, ২৬
YYYY ১৪২০, ১৪২১, ১৪২২, …, ১৪২৫, ১৪২৬
YYYYb ১৪২০ (বঙ্গাব্দ), …, ১৪২৬ (বঙ্গাব্দ)