1# clock 2 3 4The **\<clock>** component provides a clock face. 5 6> **NOTE** 7> 8> The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. 9 10## Child Components 11 12Not supported 13 14 15## Attributes 16 17In addition to the [universal attributes](js-service-widget-common-attributes.md), the following attributes are supported. 18 19| Name | Type | Default Value | Mandatory | Description | 20| ----------- | ----------- | ---- | ---- | ---------------------------------------- | 21| 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.| 22| 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.| 23| 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.| 24 25 **Table 1** ClockConfig 26 27| Name | Type | Default Value | Mandatory | Description | 28| ---------------- | -------------- | --------------- | ---- | ---------------------------------------- | 29| face | <string> | - | 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.| 30| hourHand | <string> | - | 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**.| 31| minuteHand | <string> | - | 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**.| 32| secondHand | <string> | - | 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**.| 33| digitColor | <color> | \#FF000000 | No | Text color on the clock face during the daytime (6:00 to 18:00). | 34| digitColorNight | <color> | 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**).| 35| faceNight | <string> | - | 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.| 36| hourHandNight | <string> | - | 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.| 37| minuteHandNight | <string> | - | 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.| 38| secondHandNight | <string> | - | 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.| 39| 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.| 40| 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.| 41 42 43 44 45## Styles 46 47In addition to the [universal styles](js-service-widget-common-styles.md), the following styles are supported. 48 49| Name | Type | Default Value | Mandatory | Description | 50| ----------- | -------------- | ---------- | ---- | ---------------------------------------- | 51| font-family | <string> | 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.| 52 53> **NOTE** 54> 55> 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**). 56 57 58## Events 59 60| Name | Parameter | Description | 61| ---- | ------------------- | --------- | 62| hour | {hour: number} | Triggered on the hour.| 63 64 65## Example 66 67 68```html 69<!-- xxx.hml --> 70<div class="container"> 71 <div class="row"> 72 <clock class="clk" style="font-family:Courier;" hourswest="-8" clockconfig="{{clockconfig}}"> 73 </clock> 74 <clock class="clk" style="font-family:Courier;" hourswest="4" clockconfig="{{clockconfig}}"> 75 </clock> 76 </div> 77</div> 78``` 79 80 81```css 82/* xxx.css */ 83.container { 84 flex-direction:column; 85 align-items:center; 86} 87.clk { 88 width:350px; 89 height:350px; 90} 91.row { 92 flex-direction:row; 93 align-items:center; 94 justify-content: space-around; 95 border-radius: 40px; 96 padding-top: 20px; 97 padding-bottom: 20px; 98 background-color: #4169E1; 99} 100``` 101 102 103```json 104{ 105 "data": { 106 "clockconfig": { 107 "digitRadiusRatio": 0.7, 108 "digitSizeRatio": 0.08, 109 "face": "common/clock_widget.png", 110 "hourHand": "common/clock_widget_hour.png", 111 "minuteHand": "common/clock_widget_minute.png", 112 "secondHand": "common/clock_widget_second.png", 113 "faceNight": "common/black_clock_widget.png", 114 "hourHandNight": "common/black_clock_widget_hour.png", 115 "minuteHandNight": "common/black_clock_widget_minute.png", 116 "digitColor": "#000000", 117 "digitColorNight": "#FFFFFF" 118 } 119 } 120} 121``` 122**2 x 4 widget** 123 124 125