-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(获取当前时辰()) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "" | ||
} |