{"id":25091379,"url":"https://github.com/tuyangjs/chinesehours","last_synced_at":"2026-02-06T12:18:10.597Z","repository":{"id":269558724,"uuid":"907779798","full_name":"tuyangJs/ChineseHours","owner":"tuyangJs","description":"取中国古典时间，基于十二天干地支。可以获取时辰、农历信息。","archived":false,"fork":false,"pushed_at":"2024-12-25T16:22:06.000Z","size":263,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-03T13:13:02.179Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tuyangJs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-24T11:18:23.000Z","updated_at":"2025-08-24T05:32:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"1250632e-cf7f-42c6-9936-e2cdba74319d","html_url":"https://github.com/tuyangJs/ChineseHours","commit_stats":null,"previous_names":["tuyangjs/ch_zodiac_time"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/tuyangJs/ChineseHours","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuyangJs%2FChineseHours","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuyangJs%2FChineseHours/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuyangJs%2FChineseHours/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuyangJs%2FChineseHours/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuyangJs","download_url":"https://codeload.github.com/tuyangJs/ChineseHours/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuyangJs%2FChineseHours/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29160810,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T07:18:23.844Z","status":"ssl_error","status_checked_at":"2026-02-06T07:13:32.659Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-07T13:20:04.884Z","updated_at":"2026-02-06T12:18:10.569Z","avatar_url":"https://github.com/tuyangJs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](s.png)\n\n## 取中国古典时间\n\n**天干地支时辰**‌是中国古代用来纪时的一种方法，将一天分为十二个时辰，每个时辰对应一个地支，共十二个地支：子、丑、寅、卯、辰、巳、午、未、申、酉、戌、亥。每个时辰相当于现在的两个小时。‌12\n\n### 天干地支时辰的具体时间\n\n| 时辰 | 时间范围 |\n|------|----------|\n| 子时 | 23:00 - 01:00 |\n| 丑时 | 01:00 - 03:00 |\n| 寅时 | 03:00 - 05:00 |\n| 卯时 | 05:00 - 07:00 |\n| 辰时 | 07:00 - 09:00 |\n| 巳时 | 09:00 - 11:00 |\n| 午时 | 11:00 - 13:00 |\n| 未时 | 13:00 - 15:00 |\n| 申时 | 15:00 - 17:00 |\n| 酉时 | 17:00 - 19:00 |\n| 戌时 | 19:00 - 21:00 |\n| 亥时 | 21:00 - 23:00 |\n\n### 安装\n\n```bash\nnpm i chinesehours \n```\n\n\n\n### 使用例子\n\n```typescript\nimport { GetHours } from 'chinesehours' \nconsole.log(GetHours())\n//log\n{\n  hours: 23,\n  Dzhi: '子',\n  HoursCh: '夜半',\n  minutes: 59,\n  momentType: '初',\n  Amoment: 3,\n  momentText: '子初四刻',\n  format: '子时（夜半）子初四刻'\n}\n\n```\n\n#### 返回说明\n\n- `Object`：包含公历和农历详细信息的对象。\n  - `hours`：当前小时数（24小时制）。\n  - `Dzhi`：地支名称（如“子时”）。\n  - `HoursCh`：时辰中文名称（如“鸡鸣”）。\n  - `minutes`：当前分钟数。\n  - `momentType`：刻的分类（“初”或“正”）。\n  - `Amoment`：刻数（0到3）。\n  - `momentText`：完整的时刻描述（如“子初一刻”）。\n  - `format`：格式化后的完整时间文本。\n\n#### 自定义时间格式\n\n##### 变量列表：\n\n- `地支`  - 子时\n- `时辰`  - 夜半\n- `时刻` - 子正 \u0026 子初\n\n```typescript\nimport { GetHours } from 'chinesehours' \nconsole.log(GetHours('地支：[地支] 时辰：[时辰] 时刻:[时刻]'))\n\n```\n\n#### 指定时间\n\n```typescript\nimport { GetHours } from 'chinesehours' \nconst customDate = new Date('2024-12-24T14:30:00');\nconsole.log(GetHours(customDate))\n```\n\n#### 同时自定义格式和指定时间\n\n```typescript\nimport { GetHours } from 'chinesehours' \nconst customDate = new Date('2024-12-24T14:30:00');\nconsole.log(GetHours('地支：[地支] - 时刻:[时刻]',customDate))\n```\n\n## 取中国农历\n\n`Calendar` 模块提供了公历与农历之间的转换、节日查询、节气计算等功能。以下是该模块中导出的各个函数及其使用方法。\n\n------\n\n### 使用例子\n\n```typescript\nimport { Calendar } from 'chinesehours' \nconsole.log(Calendar.solar2lunar(1987, 11, 1));\n//log\n {\n  lunarYear: 1987,\n  lunarYearCN: '一九八七',\n  lunarMonth: 9,\n  lunarDay: 10,\n  lunarMonthDays: 29,\n  fullLunarMonthString: '九月初十',\n  zodiac: '兔',\n  IMonthCn: '九月',\n  IDayCn: '初十',\n  solarYear: 1987,\n  solarYearCN: '一九八七',\n  solarMonth: 11,\n  solarDay: 1,\n  solarMonthDays: 30,\n  gzYear: '丁卯',\n  gzMonth: '庚戌',\n  gzDay: '甲寅',\n  isToday: false,\n  isLeapMonth: false,\n  isLeapYear: false,\n  nWeek: 7,\n  ncWeek: '星期日',\n  isTerm: false,\n  Term: '',\n  constellation: '天蝎座',\n  GzNy: '炉中火',\n  astroEn: 'Scorpio',\n  isFestival: false,\n  festivalName: '',\n  festivalEnName: '',\n  isLunarFestival: false\n}\n\n```\n\n[返回数据结构说明](#18-solar2lunaryear-number--string--date--dayjs-month-number--string-day-number--string)\n\n### 1. `getYearCN(year: number)`\n\n**功能描述**：将年份转换为中文表示形式（如：1989 -\u003e 一九八九）。\n\n**参数**：\n\n- `year` (`number`)：年份数字，范围为1900-2099。\n\n**返回值**：\n\n- `string`：年份的中文表示形式。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.getYearCN(1989)); // 输出：一九八九\n```\n\n------\n\n### 2. `lunarYearDays(y: number)`\n\n**功能描述**：返回农历y年的总天数。\n\n**参数**：\n\n- `y` (`number`)：年份数字，范围为1900-2099。\n\n**返回值**：\n\n- `number`：该年农历的总天数。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.lunarYearDays(1987)); // 输出：387\n```\n\n------\n\n### 3. `leapMonth(y: number)`\n\n**功能描述**：返回农历y年是否有闰月，若有则返回闰月是哪个月（1-12），否则返回0。\n\n**参数**：\n\n- `y` (`number`)：年份数字，范围为1900-2099。\n\n**返回值**：\n\n- `number`：闰月是哪个月（1-12），若无闰月则返回0。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.leapMonth(1987)); // 输出：6\n```\n\n------\n\n### 4. `leapDays(y: number)`\n\n**功能描述**：返回农历y年闰月的天数，若该年没有闰月则返回0。\n\n**参数**：\n\n- `y` (`number`)：年份数字，范围为1900-2099。\n\n**返回值**：\n\n- `number`：闰月的天数（0, 29 或 30）。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.leapDays(1987)); // 输出：29\n```\n\n------\n\n### 5. `monthDays(y: number, m: number)`\n\n**功能描述**：返回农历y年m月（非闰月）的总天数。\n\n**参数**：\n\n- `y` (`number`)：年份数字，范围为1900-2099。\n- `m` (`number`)：月份数字，范围为1-12。\n\n**返回值**：\n\n- `number`：该月的天数（29 或 30），若月份参数错误则返回-1。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.monthDays(1987, 9)); // 输出：29\n```\n\n------\n\n### 6. `solarDays(y: number, m: number)`\n\n**功能描述**：返回公历y年m月的天数。\n\n**参数**：\n\n- `y` (`number`)：年份数字，范围为1900-2099。\n- `m` (`number`)：月份数字，范围为1-12。\n\n**返回值**：\n\n- `number`：该月的天数（28, 29, 30 或 31），若月份参数错误则返回-1。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.solarDays(1987, 2)); // 输出：28\n```\n\n------\n\n### 7. `totianGandiZhiYear(lYear: number)`\n\n**功能描述**：将农历年份转换为干支纪年。\n\n**参数**：\n\n- `lYear` (`number`)：农历年份数字，范围为1900-2099。\n\n**返回值**：\n\n- `string`：干支纪年字符串。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.totianGandiZhiYear(1987)); // 输出：丁卯年\n```\n\n------\n\n### 8. `getConstellation(cMonth: number, cDay: number)`\n\n**功能描述**：根据公历月和日判断所属星座。\n\n**参数**：\n\n- `cMonth` (`number`)：公历月份，范围为1-12。\n- `cDay` (`number`)：公历日期，范围为1-31。\n\n**返回值**：\n\n- `string`：星座的中文名称。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.getConstellation(3, 21)); // 输出：白羊座\n```\n\n------\n\n### 9. `getFestival(solarMonth: number, solarDay: number, lunarMonth: number, lunarDay: number, isTerm: boolean, term: string | undefined, lunarYear: number)`\n\n**功能描述**：根据公历月份、公历日期、农历月份、农历日期、节气判断是否为节日，并返回节日对象。\n\n**参数**：\n\n- `solarMonth` (`number`)：公历月份，范围为1-12。\n- `solarDay` (`number`)：公历日期，范围为1-31。\n- `lunarMonth` (`number`)：农历月份，范围为1-12。\n- `lunarDay` (`number`)：农历日期，范围为1-30。\n- `isTerm` (`boolean`)：是否为节气。\n- `term` (`string | undefined`)：节气名称。\n- `lunarYear` (`number`)：农历年份数字，范围为1900-2099。\n\n**返回值**：\n\n- `Festival`：节日对象，包含节日信息。\n\n**示例**：\n\n```typescript\nconst festival = Calendar.getFestival(1, 1, 11, 1, false, undefined, 1987);\nconsole.log(festival); // 输出：{ ... }\n```\n\n------\n\n### 10. `totianGandiZhi(offset: number)`\n\n**功能描述**：根据偏移量返回对应的干支。\n\n**参数**：\n\n- `offset` (`number`)：相对甲子的偏移量。\n\n**返回值**：\n\n- `string`：干支字符串。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.totianGandiZhi(1)); // 输出：乙丑\n```\n\n------\n\n### 11. `getTerm(y: number, n: number)`\n\n**功能描述**：获取公历y年第n个节气的日期。\n\n**参数**：\n\n- `y` (`number`)：年份数字，范围为1900-2099。\n- `n` (`number`)：节气序号，范围为1-24。\n\n**返回值**：\n\n- `number`：节气的日期。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.getTerm(1987, 3)); // 输出：4\n```\n\n------\n\n### 12. `toChinaMonth(m: number)`\n\n**功能描述**：将农历月份转换为中文表示形式。\n\n**参数**：\n\n- `m` (`number`)：月份数字，范围为1-12。\n\n**返回值**：\n\n- `string`：农历月份的中文表示形式。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.toChinaMonth(12)); // 输出：腊月\n```\n\n------\n\n### 13. `toChinaDay(d: number)`\n\n**功能描述**：将农历日期转换为中文表示形式。\n\n**参数**：\n\n- `d` (`number`)：日期数字，范围为1-30。\n\n**返回值**：\n\n- `string`：农历日期的中文表示形式。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.toChinaDay(21)); // 输出：廿一\n```\n\n------\n\n### 14. `getAnimal(y: number)`\n\n**功能描述**：根据年份返回生肖。\n\n**参数**：\n\n- `y` (`number`)：年份数字，范围为1900-2099。\n\n**返回值**：\n\n- `string`：生肖的中文名称。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.getAnimal(1987)); // 输出：兔\n```\n\n------\n\n### 15. `isLeapYear(solarYear: number): boolean | string`\n\n**功能描述**：判断公历年份是否为闰年。\n\n**参数**：\n\n- `solarYear` (`number`)：公历年份数字，范围为1901-2099。\n\n**返回值**：\n\n- `boolean | string`：如果是闰年返回 `true`，否则返回 `false`；如果年份不在合法范围内则返回提示字符串。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.isLeapYear(1987)); // 输出：false\n```\n\n------\n\n### 16. `countSolarMonthDays(solarYear: number, solarMonth: number): number | string`\n\n**功能描述**：返回公历某年某月的天数。\n\n**参数**：\n\n- `solarYear` (`number`)：公历年份数字，范围为1900-2099。\n- `solarMonth` (`number`)：公历月份数字，范围为1-12。\n\n**返回值**：\n\n- `number | string`：该月的天数；如果输入参数不合法则返回提示字符串。\n\n**示例**：\n\n```typescript\n\nconsole.log(Calendar.countSolarMonthDays(1987, 7)); // 输出：31\n```\n\n------\n\n### 17. `getAllFestival(solarYear: number | string)`\n\n**功能描述**：获取某年所有的节日列表。\n\n**参数**：\n\n- `solarYear` (`number | string`)：公历年份数字或字符串，范围为1901-2099。\n\n**返回值**：\n\n- `Array\u003cFestival\u003e`：节日对象数组。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.getAllFestival(1987));\n```\n\n------\n\n### 18. `solar2lunar(Year?: number | string | Date | Dayjs, Month?: number | string, Day?: number | string)`\n\n**功能描述**：将公历日期转换为农历日期，并返回详细的农历信息。\n\n**参数**：\n\n- `Year` (`number | string | Date | Dayjs`)：年份，可以是数字、字符串、Date 对象或 Dayjs 对象。\n- `Month` (`number | string`)：月份，可以是数字或字符串。\n- `Day` (`number | string`)：日期，可以是数字或字符串。\n\n**返回值**：\n\n- `Object`：包含公历和农历详细信息的对象。\n  - `lunarYear`: 农历年份\n  - `lunarYearCN`:农历年份的中文表示，即将数字1987分开并用汉字表示：一九八七。\n  - `lunarMonth`: 农历月份。\n  - `lunarDay`: 10 农历日期，这个日期是农历的初十，即九月十日。\n  - `lunarMonthDays`: 农历月份的天数，农历的九月有29天。\n  - `fullLunarMonthString`: 完整的农历日期字符串。\n  - `zodiac`: 生肖\n  - `IMonthCn`: 农历月份的中文名称\n  - `IDayCn`: 农历日期的中文名称，即初十。\n  -  `solarYear`: 1987 公历年份，1987年是公历年份。\n  -  `solarYearCN`: 公历年份的中文表示，即一九八七。\n  -  `solarMonth`: 公历月份。\n  -  `solarDay`: 公历日期。\n  -  `solarMonthDays`: 公历月份的天数\n  -  `gzYear`: 地支年份\n  -  `gzMonth`: 天干地支月份\n  -  `gzDay`: 天干地支日期。\n  -  `isToday`: 是否是今天。\n  -  `isLeapMonth`: 是否是闰月。\n  -  `isLeapYear`: 是否是闰年。\n  -  `nWeek`: 星期几的数字表示，7表示星期天。\n  -  `ncWeek`: 星期几的中文表示，即星期日。\n  -  `isTerm`: 是否是节气。\n  -  `Term`: 节气名称。\n  -  `constellation`: 星座，根据公历日期。\n  -  `GzNy`: 五行，此日期的五行是炉中火。\n  -  `astroEn`: 星座的英文表示。\n  -  `isFestival`: 是否是节日。\n  -  `festivalName`: 节日名称。\n  -  `festivalEnName`: 节日的英文名称。\n  -  `isLunarFestival`: 是否是农历节日。\n\n```typescript\nconsole.log(Calendar.solar2lunar(1987, 11, 1));\n```\n\n------\n\n### 19. `lunar2solar(year: number, month: number, date: number, isLeapM: boolean)`\n\n**功能描述**：将农历日期转换为公历日期，并返回详细的公历信息。\n\n**参数**：\n\n- `year` (`number`)：年份数字，范围为1901-2099。\n- `month` (`number`)：月份数字，范围为1-12。\n- `date` (`number`)：日期数字，范围为1-30。\n- `isLeapM` (`boolean`)：是否为闰月。\n\n**返回值**：\n\n- `Object`：包含公历和农历详细信息的对象。\n\n**示例**：\n\n```typescript\nconsole.log(Calendar.lunar2solar(1987, 9, 10, false));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuyangjs%2Fchinesehours","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuyangjs%2Fchinesehours","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuyangjs%2Fchinesehours/lists"}