Last Updated on : 2024-06-05 03:14:36download
This topic describes the utility methods related to time.
parseSecond
Convert the specified number of seconds to an array in which each element is a 2-digit string.
Name | Data type | Description | Required |
---|---|---|---|
second | number | The specified number of seconds. | Yes |
num | number | The length of each string in the returned array. Default value: 2 . |
No |
Name | Data type | Description |
---|---|---|
time | string | The returned array in which the length of each string is specified by num . |
import { Utils } from "tuya-panel-kit";
const { parseSecond } = Utils.TimeUtils;
parseSecond(second, num);
// Example
parseSecond(111);
parseSecond(3333333);
['00', '01', '51']
['25', '55', '33']
parseHour12
Convert the specified number of seconds to the 12-hour time that is indicated by the specified number.
Name | Data type | Description | Required |
---|---|---|---|
num | number | The specified number of seconds. | Yes |
Name | Data type | Description |
---|---|---|
time | string | The 12-hour time that is indicated by the specified number. |
import { Utils } from "tuya-panel-kit";
const { parseHour12 } = Utils.TimeUtils;
parseHour12(num);
// Example:
parseHour12(111);
parseHour12(3333333);
'01:55 AM'
'12:01 PM'
stringToSecond
Convert a specified time point to a number of seconds.
Name | Data type | Description | Required |
---|---|---|---|
timeStr | string | The specified date string. | Yes |
Name | Data type | Description |
---|---|---|
number | number | The number of seconds between the specified time point and 00:00:00 . |
import { Utils } from "tuya-panel-kit";
const { stringToSecond } = Utils.TimeUtils;
stringToSecond(timeStr);
// Example:
stringToSecond("11:30");
stringToSecond("22:11:30");
690
79890
dateToTimer
Convert a specified date string to a number of seconds.
Name | Data type | Description | Required |
---|---|---|---|
dateStr | string | The specified date string. | Yes |
Name | Data type | Description |
---|---|---|
number | number | The 10-digit value that is converted from dateStr . Unit: seconds. |
import { Utils } from "tuya-panel-kit";
const { dateToTimer } = Utils.TimeUtils;
dateToTimer(dateStr);
// Example:
dateToTimer("20110801");
1312128000
dateFormat
Convert the current time point to a string in the specified format.
Name | Data type | Description | Required |
---|---|---|---|
dateFormate | string | The month (M ), day (d ), hour (h ), minute (m ), second (s ), and quarter (q ) can use 1–2 placeholders. The year (y ) can use 1–4 placeholders. Only one placeholder is used for milliseconds (S ) to return a 1 to 3-digit number. |
Yes |
Name | Data type | Description |
---|---|---|
date | string | The string in the specified format that is converted from the current time point. |
import { Utils } from "tuya-panel-kit";
const { dateFormat } = Utils.TimeUtils;
dateFormat(format, date);
// Example:
new Date().Format("yyyy-MM-dd hh:mm:ss.S");
new Date().Format("yyyy-M-d h:m:s.S");
2006-07-02 08:09:04.423
2006-7-2 8:9:4.18
timezone
Get the current time zone.
None.
Name | Data type | Description |
---|---|---|
result | string | The current time zone. |
import { Utils } from "tuya-panel-kit";
const { timezone } = Utils.TimeUtils;
timezone();
+08:00
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback