tw-year-transform
v1.0.12
Published
tw-year-transform
Downloads
16
Readme
tw-year-transform
- 西元年和民國年互換的一些轉換方式
- Here are some methods for converting between AD years and ROC years.
Dependencies
- typescript: 5.4.3
- moment: 2.30.1
Install
npm i tw-year-transform
Usage
import { momentToTwYear } from 'tw-year-transform'
stringToTwYear
將西元年轉換為民國年回傳,有時間或沒時間都適用。 Transform a date-time string from AD year to ROC year, regardless of whether there is a time included.
stringToTwYear('2023-12-34 12:34:56') return '112-12-34 12:34:56'
stringToTwYear('2023-12-34') return '112-12-34'
stringToTwYear('2023-12') return '112-12'
stringToTwYear(null) return null
momentToTwYear
將日期時間取 moment 後轉換為民國年回傳,有時間或沒時間都適用。 Transform a date-time using Moment.js and then convert it from AD year to ROC year, regardless of whether there is a time included."
momentToTwYear('2023-12-12T12:34:56') //return '112-12-12 12:34:56'
momentToTwYear('2023-12-12') //return '112-12-12 00:00:00'
momentToTwYear('2023-12-12','YYYY-MM-DD') //return '112-12-12'
momentToTwYear(null) //return null
intervalToTwYear
將時間區間轉換為民國年回傳,時間區間用~分隔。 Convert a date-time interval from AD year to ROC year, where the interval is separated by '~'.
intervalToTwYear("2023-11-03 00:00 ~ 2023-11-06 10:30") //return "112-11-03 00:00 ~ 112-11-06 10:30"
getTwYearTimestamp
取得民國年時間戳記(可用於匯出檔案、下載檔案之檔案名稱) Get the current date-time in ROC year timestamp format, suitable for use in exporting or downloading files with the file name.
- if now is 2023-12-06 12:34:56
getTwYearTimestamp() //return "1121206123456"
TwYearToAD
將民國年字串轉為西元年字串 Convert a ROC year string to an AD year string.
TwYearToAD('112-12-34 12:34:56') //return '2023-12-34 12:34:56'
TwYearToAD('112-12-34') //return '2023-12-34'
TwYearToAD(null) //return null