Skip to main content
版本:v3

TIME

创建传感器

const time = hmSensor.createSensor(hmSensor.id.TIME)

time 实例

time: object

属性说明类型
utc时间戳, 1970 年 1 月 1 日至今的毫秒数number
yearnumber
monthnumber
daynumber
hour小时number
minute分钟number
secondnumber
week星期 1 - 7number
lunar_year中国农历年份number
lunar_month中国农历月份number
lunar_day中国农历日期number
lunar_festival中国农历节日string
lunar_solar_term中国农历节气string
solar_festival公历节日string

time.getLunarMonthCalendar

获取中国农历月历信息

const lunar_month_cal = time.getLunarMonthCalendar()

for (let i = 0; i < lunar_month_cal.day_count; i++) {
console.log('lunar_day : ' + lunar_month_cal.lunar_days_array[i])
}

time.getShowFestival

获取当天显示的节日(优先级依次是 公历节日、中国农历节日、中国农历节气)

const current_festival = time.getShowFestival()

代码示例

// 创建传感器
const jstime = hmSensor.createSensor(hmSensor.id.TIME)

console.log(
'The time utc: ' +
jstime.utc +
' year: ' +
jstime.year +
' month: ' +
jstime.month +
' day: ' +
jstime.day +
' hour: ' +
jstime.hour +
' minute: ' +
jstime.minute +
' second: ' +
jstime.second +
'\r\n'
)