1e41f4b71Sopenharmony_ci# clock
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciThe **\<clock>** component provides a clock face.
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci> **NOTE**
7e41f4b71Sopenharmony_ci>
8e41f4b71Sopenharmony_ci> The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Child Components
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciNot supported
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## Attributes
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciIn addition to the [universal attributes](js-service-widget-common-attributes.md), the following attributes are supported.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci| Name         | Type         | Default Value | Mandatory  | Description                                      |
20e41f4b71Sopenharmony_ci| ----------- | ----------- | ---- | ---- | ---------------------------------------- |
21e41f4b71Sopenharmony_ci| clockconfig | ClockConfig | -    | Yes   | Image resources and styles used by this **\<clock>** component, including one set for the daytime (6:00 to 18:00) and one set for the nighttime (18:00 to 6:00 of the next day).<br>Each set of resources contains four images for the clock face, hour hand, minute hand, and second hand, respectively. Each set of styles is used for specifying number colors for the daytime and nighttime.<br>This attribute is mandatory for the daytime. If you do not set this attribute for the nighttime, the daytime images are reused at the nighttime.<br>Object members cannot be dynamically updated. However, You can dynamically update the object.<br>You are advised to use PNG images.<br>SVG images are not supported.|
22e41f4b71Sopenharmony_ci| showdigit   | boolean     | true | No   | Whether to draw clock face numbers based on **clockconfig**.<br>If you set this attribute to **true**, ensure that **digitRadiusRatio** and **digitSizeRatio** parameters of **clockconfig** match the clock face.<br>The numbers generated by the **\<clock>** component support multiple number formats in different locales.|
23e41f4b71Sopenharmony_ci| hourswest   | number      | -    | No   | Time offset of the clock to the Coordinated Universal Time (UTC). The local time zone is UTC minus **hourswest**.<br>The value range is [-12, 12]. For example, the value **-8** means UTC+8. If this parameter is not set, the current system time zone is used.|
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci  **Table 1** ClockConfig
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci| Name              | Type            | Default Value            | Mandatory  | Description                                      |
28e41f4b71Sopenharmony_ci| ---------------- | -------------- | --------------- | ---- | ---------------------------------------- |
29e41f4b71Sopenharmony_ci| face             | &lt;string&gt; | -               | Yes   | Path of clock face images used in the daytime.<br>The clock face resources must be square images that contain the clock scale, and the clock face area must be an inscribed circle of the image or a concentric circle of the inscribed circle. If the clock face area is a concentric circle of the inscribed circle, you need to change the **digitRadiusRatio** and **digitSizeRatio** values accordingly.|
30e41f4b71Sopenharmony_ci| hourHand         | &lt;string&gt; | -               | Yes   | Path of hour hand images used in the daytime.<br>- The height of the hour hand images must be the same as that of the clock face images.<br>- You are advised to set the aspect ratio of the hour hand images to **0.062**.<br>- The rotation center of the hour hand must be the same as the center (diagonal intersection point) of the hour hand images.<br>- To specify the hour hand resources for the nighttime, set **hourHandNight**.|
31e41f4b71Sopenharmony_ci| minuteHand       | &lt;string&gt; | -               | Yes   | Path of minute hand images used in the daytime.<br>- The height of the minute hand images must be the same as that of the clock face images.<br>- You are advised to set the aspect ratio of the minute hand images to **0.062**.<br>- The rotation center of the minute hand must be the same as the center (diagonal intersection point) of the minute hand images.<br>- To specify the minute hand resources for the nighttime, set **minuteHandNight**.|
32e41f4b71Sopenharmony_ci| secondHand       | &lt;string&gt; | -               | Yes   | Path of second hand images used in the daytime.<br>- The height of the second hand images must be the same as that of the clock face images.<br>- You are advised to set the aspect ratio of the second hand images to **0.062**.<br>- The rotation center of the second hand must be the same as the center (diagonal intersection point) of the second hand images.<br>- To specify the second hand resources for the nighttime, set **secondHandNightSrc**.|
33e41f4b71Sopenharmony_ci| digitColor       | &lt;color&gt;  | \#FF000000      | No   | Text color on the clock face during the daytime (6:00 to 18:00).                |
34e41f4b71Sopenharmony_ci| digitColorNight  | &lt;color&gt;  | Same as that of **digitColor**| No   | Text color on the clock face during the nighttime (18:00 to 06:00 of the following day).<br>- If this attribute is not set, the value of **digitColor** is used as the value of **digitColorNight**.<br>In this case, you should ensure the text color of the nighttime clock face matches the color of the nighttime clock face images (stored in **faceNight**).|
35e41f4b71Sopenharmony_ci| faceNight        | &lt;string&gt; | -               | No   | Path of clock face images used in the nighttime.<br>If this parameter is not set, the path of clock face images for the daytime is used as the value of this parameter.|
36e41f4b71Sopenharmony_ci| hourHandNight    | &lt;string&gt; | -               | No   | Path of hour hand images used in the nighttime.<br>If this parameter is not set, the path of hour hand images for the daytime is used as the value of this parameter.|
37e41f4b71Sopenharmony_ci| minuteHandNight  | &lt;string&gt; | -               | No   | Path of minute hand images used in the nighttime.<br>If this parameter is not set, the path of minute hand images for the daytime is used as the value of this parameter.|
38e41f4b71Sopenharmony_ci| secondHandNight  | &lt;string&gt; | -               | No   | Path of second hand images used in the nighttime.<br>If this parameter is not set, the path of second hand images for the daytime is used as the value of this parameter.|
39e41f4b71Sopenharmony_ci| digitRadiusRatio | number         | 0.7             | No   | Distance between the center of the clock face numbers and the center of the clock face circle/Half of the side length of the clock face image.<br>- The value range is (0, 1].<br>- This parameter is used to calculate the distance between the numbers on the clock face and the center of the clock face circle.<br>- This parameter ensures that the same set of clock face images have the same relative position in components of different sizes. You do not need to change the position for components of different sizes.<br>- If this parameter is set to **1**, the numbers may exceed the clock face area. In this case, you should change the **digitRadiusRatio** value based on the clock face size.|
40e41f4b71Sopenharmony_ci| digitSizeRatio   | number         | 0.08            | No   | Font size of the watch face numbers/Side length of the watch face<br>- The value range is (0, 0.142].<br>- This parameter is used to calculate the font size of clock face numbers relative to the size of the clock face.<br>- This parameter ensures that the same set of clock face images have the same relative size in components of different sizes. You do not need to change the font size for components of different sizes.|
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci![clock](figures/clock.png)
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci## Styles
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ciIn addition to the [universal styles](js-service-widget-common-styles.md), the following styles are supported.
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci| Name         | Type            | Default Value       | Mandatory  | Description                                      |
50e41f4b71Sopenharmony_ci| ----------- | -------------- | ---------- | ---- | ---------------------------------------- |
51e41f4b71Sopenharmony_ci| font-family | &lt;string&gt; | sans-serif | No   | Font family used for clock face numbers, in which fonts are separated by commas (,). Each font is set using a font name or font family name. The first font in the family or the font specified by a custom font style is used for the text.|
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci>  **NOTE**
54e41f4b71Sopenharmony_ci>
55e41f4b71Sopenharmony_ci>  The **\<clock>** component keeps the aspect ratio of the display area to **1**. The side length of the final square display area is **min(width, height)**. The square display area is centered in the component (**width** x **height**).
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci## Events
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci| Name  | Parameter                 | Description       |
61e41f4b71Sopenharmony_ci| ---- | ------------------- | --------- |
62e41f4b71Sopenharmony_ci| hour | {hour: number} | Triggered on the hour.|
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci## Example
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci```html
69e41f4b71Sopenharmony_ci<!-- xxx.hml -->
70e41f4b71Sopenharmony_ci<div class="container">
71e41f4b71Sopenharmony_ci    <div class="row">
72e41f4b71Sopenharmony_ci        <clock class="clk" style="font-family:Courier;" hourswest="-8" clockconfig="{{clockconfig}}">
73e41f4b71Sopenharmony_ci        </clock>
74e41f4b71Sopenharmony_ci        <clock class="clk" style="font-family:Courier;" hourswest="4" clockconfig="{{clockconfig}}">
75e41f4b71Sopenharmony_ci        </clock>
76e41f4b71Sopenharmony_ci    </div>
77e41f4b71Sopenharmony_ci</div>
78e41f4b71Sopenharmony_ci```
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci```css
82e41f4b71Sopenharmony_ci/* xxx.css */ 
83e41f4b71Sopenharmony_ci.container {
84e41f4b71Sopenharmony_ci    flex-direction:column;
85e41f4b71Sopenharmony_ci    align-items:center;
86e41f4b71Sopenharmony_ci}
87e41f4b71Sopenharmony_ci.clk {
88e41f4b71Sopenharmony_ci    width:350px;
89e41f4b71Sopenharmony_ci    height:350px;
90e41f4b71Sopenharmony_ci}
91e41f4b71Sopenharmony_ci.row {
92e41f4b71Sopenharmony_ci    flex-direction:row;
93e41f4b71Sopenharmony_ci    align-items:center;
94e41f4b71Sopenharmony_ci    justify-content: space-around;
95e41f4b71Sopenharmony_ci    border-radius: 40px;
96e41f4b71Sopenharmony_ci    padding-top: 20px;
97e41f4b71Sopenharmony_ci    padding-bottom: 20px;
98e41f4b71Sopenharmony_ci    background-color: #4169E1;
99e41f4b71Sopenharmony_ci}
100e41f4b71Sopenharmony_ci```
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci```json
104e41f4b71Sopenharmony_ci{
105e41f4b71Sopenharmony_ci  "data": {
106e41f4b71Sopenharmony_ci    "clockconfig": {
107e41f4b71Sopenharmony_ci      "digitRadiusRatio": 0.7,
108e41f4b71Sopenharmony_ci      "digitSizeRatio": 0.08,
109e41f4b71Sopenharmony_ci      "face": "common/clock_widget.png",
110e41f4b71Sopenharmony_ci      "hourHand": "common/clock_widget_hour.png",
111e41f4b71Sopenharmony_ci      "minuteHand": "common/clock_widget_minute.png",
112e41f4b71Sopenharmony_ci      "secondHand": "common/clock_widget_second.png",
113e41f4b71Sopenharmony_ci      "faceNight": "common/black_clock_widget.png",
114e41f4b71Sopenharmony_ci      "hourHandNight": "common/black_clock_widget_hour.png",
115e41f4b71Sopenharmony_ci      "minuteHandNight": "common/black_clock_widget_minute.png",
116e41f4b71Sopenharmony_ci      "digitColor": "#000000",
117e41f4b71Sopenharmony_ci      "digitColorNight": "#FFFFFF"
118e41f4b71Sopenharmony_ci    }
119e41f4b71Sopenharmony_ci  }
120e41f4b71Sopenharmony_ci}
121e41f4b71Sopenharmony_ci```
122e41f4b71Sopenharmony_ci**2 x 4 widget**
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci![clockshow](figures/clockshow.png)
125