Open In App

Moment.js Taiwan Calendar Plugin

Last Updated : 20 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Moment-Taiwan plugin is used to support the Taiwan calendar used in Taiwan and China. It allows seamless integration of Moment.js with the calendar.

Calendar Conversions between Gregorian and Taiwan are as follows:

Gregorian to Taiwan:

year < 1911 : year - 1912
year > 1911 : year - 1911

Taiwan to Gregorian:

year >= 1 : year + 1911
year == 0 : 1912
year < 0 : year + 1912

This package can be installed by using the following command:

npm install moment-taiwan

Parameters: This plugin does not accept any parameters.

Return Value: This plugin returns dates in Taiwan to Gregorian or Gregorian to Taiwan.

The below examples will demonstrate the usage of this plugin.

Example 1: Using tYY to format or parse the datetime string.

Javascript




const tw = require('moment-taiwan');
 
// Converting Taiwan to Gregorian
let date = tw('108/10/20', 'tYY/MM/DD');
console.log(date.format('tYY/MM/DD [is] YYYY/M/D'))


Output:

108/10/20 is 2019/10/20

Example 2: Using tYY to format or parse the datetime string.

Javascript




const tw = require('moment-taiwan');
 
// Converting Taiwan to Gergorian
let date = tw('98/10/20', 'tYY/MM/DD');
console.log(date.format('tYY/MM/DD [is] YYYY/M/D'))


Output:

98/10/20 is 2009/10/20

Reference: https://momentjs.com/docs/#/plugins/taiwan/


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads