Skip to main content
Version: v3

Time

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Time/Date Sensor.

Methods

getTime

Gets the UTC timestamp in milliseconds

getTime(): number

getFullYear

Get the year of the current date

getFullYear(): number

getMonth

Get the month of the current date, range 1 - 12, return 1 for January

getMonth(): number

getDate

Get the number of days of the current date, i.e. the day of the month, in the range 1 - 31

getDate(): number

getHours

Get the number of hours of the current time

getHours(): number

getMinutes

Get the number of minutes of the current time

getMinutes(): number

getSeconds

Get the number of seconds of the current time

getSeconds(): number

getDay

Get the current time corresponding to the day of the week, range 1 - 7, return 1 for Monday

getDay(): number

getHourFormat

Start from API_LEVEL 2.1

Get the current system time format, 12-hour format or 24-hour format,value reference hour format constants

getHourFormat(): number

Constants

Hour format constants
ConstantDescriptionAPI_LEVEL
TIME_HOUR_FORMAT_1212-hour format2.1
TIME_HOUR_FORMAT_2424-hour format2.1

getFormatHour

Start from API_LEVEL 2.1

Get the number of hours in the current time format (12-hour format or 24-hour format)

getFormatHour(): number

onPerMinute

Start from API_LEVEL 2.1

Register end-of-minute event listener callback function

onPerMinute(callback: () => void): void

onPerDay

Start from API_LEVEL 2.1

Register the end-of-day event listener callback function

onPerDay(callback: () => void): void

getFestival

Get gregorian holidays, or return the string 'INVALID' if there is no holiday

getFestival(): string

getLunarYear

Get Chinese lunar year, only works when system language is set to Chinese

getLunarYear(): number

getLunarMonth

Get Chinese lunar month, only works when system language is set to Chinese

getLunarMonth(): number

getLunarDay

Get Chinese lunar day, only works when system language is set to Chinese

getLunarDay(): number

getLunarFestival

Get Chinese lunar holidays, only works when system language is set to Chinese, or return the string 'INVALID' if there is no holiday

getLunarFestival(): string

getSolarTerm

Get Traditional Chinese Solar Terms, only works when system language is set to Chinese, or return the string 'INVALID' if there is no Solar Term

getSolarTerm(): string

getShowFestival

Get the holiday strings displayed on that day, the priority is Gregorian holidays, Chinese lunar holidays, Chinese lunar festivals in that order, only when the system language is set to Chinese

getShowFestival(): string

getLunarMonthCalendar

Get the monthly calendar information of the current month of Chinese lunar calendar, only works when the system language is set to Chinese

getLunarMonthCalendar(): LunarMonthCalendar

LunarMonthCalendar

PropertyTypeDescriptionAPI_LEVEL
day_countnumberNumber of days in the current month2.0
lunar_days_arrayArray<string>Array of display content for each day of the current month, display content priority for holidays, Solar Term, date2.0

onSunrise

Start from API_LEVEL 3.0

Register the Sunrise event listener callback function to take effect only when the device weather information

onSunrise(callback: () => void): void

onSunset

Start from API_LEVEL 3.0

Register the Sunset event listener callback function to take effect only when the device weather information

onSunset(callback: () => void): void

onPhoneTimeSetting

Start from API_LEVEL 3.0

Register the phone modify time event listening callback function

onPhoneTimeSetting(callback: () => void): void

Example

import { Time } from '@zos/sensor'

const time = new Time()
const currentTime = time.getTime()