diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/index.js b/index.js new file mode 100644 index 0000000..b25d239 --- /dev/null +++ b/index.js @@ -0,0 +1,24 @@ +function 获取当前时辰(format, currentTime) { + format = format ? format : "地支(时辰)时刻" + currentTime = currentTime ? currentTime : new Date + + // 获取小时和分钟 + const hours = currentTime.getHours(); + let minutes = currentTime.getMinutes(); + + const 十二地支 = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"] + const 十二辰时 = ["夜半", "鸡鸣", "平旦", "日出", "食时", "隅中", "日平", "日昳", "晡时", "日入", "黄昏", "人定"] + const CNint = ['一', '二', '三', '四', '五', '六', '七', '八'] + const i = TimeIndex(hours) + minutes = (TimeIndex(hours - 1) === i) ? (60 + minutes) : minutes //计算是否延长分钟大于60 + const 刻 = Math.floor(minutes / 15) // 每时辰划分为8刻 + + format = format.replace("地支", 十二地支[i] + '时') + format = format.replace("时辰", 十二辰时[i]) + format = format.replace("时刻", CNint[刻] + '刻') + function TimeIndex(h) { + return Math.floor((h + 1) / 2 ) + } + return format +} +console.log(获取当前时辰()) \ No newline at end of file diff --git a/main/index.js b/main/index.js new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json new file mode 100644 index 0000000..a2a87fa --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "zodiac_time", + "version": "1.0.0", + "main": "index.js", + "module": "main/index.js", + "private": false, + "type": "module", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "description": "" +} \ No newline at end of file diff --git a/s.png b/s.png new file mode 100644 index 0000000..9b73290 Binary files /dev/null and b/s.png differ