Skip to content

将公历年份转化为农历(天干地支)年份

Robert Yao edited this page Jul 2, 2019 · 1 revision
/**
 * 将公历年份转化为农历(天干地支)年份
 * ========================================================================
 * @param {String|Number} time - 表示时间的字符串或者数值
 * @returns {string}
 */
const getLunarYear = (time) => {
  const HEAVENLY_STEMS = [
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    ''
  ]
  const EARTHLY_BRANCHES = [
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    '',
    ''
  ]
  let diff = new Date(time).getFullYear() - 1864

  return HEAVENLY_STEMS[diff % 10] + EARTHLY_BRANCHES[diff % 12]
}
You can’t perform that action at this time.