Time synchronization method and device
By detecting the time offset in the local system and generating a reasonable time synchronization interval, the problem of waste of communication resources caused by frequent time synchronization in the prior art is solved, and the efficiency and accuracy of time synchronization are achieved.
Patent Information
- Application Number
- CN202011237829.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-09
- Publication Date
- 2025-02-21
- Estimated Expiration
- 2040-11-09
AI Technical Summary
The existing time synchronization method has the problem of wasting communication resources, especially when time synchronization requests are frequently made.
By detecting the time synchronization command, sending a time synchronization request and receiving the time synchronization information returned by the server, and updating the local system time to the server time. Based on the time offset between the current time and the server time, the time synchronization interval is generated to avoid frequent time synchronization requests.
It effectively reduces the waste of communication resources, ensures the synchronization of local system time and server time, and avoids the instability caused by the frequent execution of time synchronization requests by the system.
Smart Images

Figure CN112346512B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, specifically to the field of information maintenance technology, and especially to a time synchronization method and device. Background Art
[0002] Time consistency between devices is an important prerequisite for mutual communication or mutual control between devices. At present, the main method for time synchronization between devices is: the devices initiate time synchronization requests at preset time intervals to perform time synchronization.
[0003] However, current time synchronization methods suffer from the problem of wasting communication resources. Summary of the invention
[0004] The present disclosure provides a time synchronization method, device, electronic device, and computer-readable storage medium.
[0005] According to a first aspect of the present disclosure, a time synchronization method is provided, comprising: in response to detecting a time synchronization instruction, executing the following time synchronization steps: sending a time synchronization request, wherein the time synchronization request includes a current time read from a local system; receiving time synchronization information for determining a server time based on the time synchronization request return; updating the time of the local system to the server time based on the time synchronization information; generating a time synchronization interval duration based on a time offset between the read current time and the server time; and obtaining the current time from the local system; in response to determining that the duration from the obtained current time to executing the time synchronization step is the time synchronization interval duration, generating a time synchronization instruction.
[0006] In some embodiments, a time synchronization interval duration is generated based on a time offset between a current time read and a server time, including: in response to determining that a time synchronization request currently sent is not a time synchronization request sent for the first time, obtaining multiple historical time offsets; determining a time offset mean based on multiple historical time offsets; and using the difference between the time offset mean and a preset time interval duration base as the time synchronization interval duration.
[0007] In some embodiments, based on multiple historical time offsets, a mean time offset is determined, including: in response to detecting that the number of multiple historical time offsets is less than or equal to a preset number, the multiple historical time offsets are arranged in ascending order to form a first array; and the historical time offsets located in a first target sequence in the first array are determined as the mean time offset, wherein the first target sequence is determined based on the number of historical time offsets.
[0008] In some embodiments, a time offset mean is determined based on multiple historical time offsets, including: in response to detecting that the number of multiple historical time offsets is greater than a preset number, arranging multiple historical time offsets determined based on the most recent preset number of time synchronization requests in ascending order to form a second array; determining the historical time offsets located in a second target sequence in the second array as the time offset mean, wherein the second target sequence is determined based on the preset number.
[0009] In some embodiments, the difference between a preset time interval duration base and a time offset mean is used as the time synchronization interval duration, including: obtaining the request time for sending a time synchronization request and the response time for receiving the time synchronization information; determining the duration between the request time and the response time as the delay duration; and determining the remaining duration after deducting the delay duration from the preset time interval duration base and the time offset mean as the time synchronization interval duration.
[0010] In some embodiments, a time synchronization interval duration is generated based on the time offset between the read current time and the server time, including: in response to detecting that the time synchronization interval duration is less than a preset minimum time interval duration, determining the preset minimum time interval duration as the calibrated time synchronization interval duration.
[0011] In some embodiments, receiving time synchronization information indicating server time returned based on a time synchronization request includes: in response to determining that a currently sent time synchronization request is a first sent time synchronization request, receiving server time returned based on the time synchronization request.
[0012] In some embodiments, based on the time synchronization information, the local system time is updated to the server time, including: obtaining the average download time for the local system to download data; determining the server time based on the server system time indicated by the time synchronization information and the average download time, and updating the local system time to the server time.
[0013] According to a second aspect of the present disclosure, a time synchronization device is provided, comprising: a synchronization unit, configured to, in response to detecting a time synchronization instruction, perform the following time synchronization steps: sending a time synchronization request, wherein the time synchronization request includes a current time read from a local system; receiving time synchronization information for determining a server time returned based on the time synchronization request; updating the time of the local system to the server time based on the time synchronization information; a duration generation unit, configured to generate a time synchronization interval duration based on a time offset between the read current time and the server time; and an acquisition unit, configured to acquire the current time from the local system; an instruction generation unit, configured to generate a time synchronization instruction in response to determining that the duration from the acquired current time to executing the time synchronization step is the time synchronization interval duration.
[0014] In some embodiments, the duration generation unit includes: an acquisition module, configured to acquire multiple historical time offsets in response to determining that a time synchronization request currently sent is not a time synchronization request sent for the first time; a first determination module, configured to determine a time offset mean based on multiple historical time offsets; and a second determination module, configured to use the difference between the time offset mean and a preset time interval duration base as the time synchronization interval duration.
[0015] In some embodiments, a first determination module includes: a first sorting module, configured to arrange multiple historical time offsets in ascending order to form a first array in response to detecting that the number of multiple historical time offsets is less than or equal to a preset number; a first determination submodule, configured to determine the historical time offsets located in a first target sequence in the first array as the mean of the time offsets, wherein the first target sequence is determined based on the number of historical time offsets.
[0016] In some embodiments, a first determination module includes: a second sorting module, configured to, in response to detecting that the number of multiple historical time offsets is greater than a preset number, arrange the multiple historical time offsets determined based on the most recent preset number of time synchronization requests in ascending order to form a second array; a second determination submodule, configured to determine the historical time offsets of a second target sequence in the second array as the mean of the time offsets, wherein the second target sequence is determined based on the preset number.
[0017] In some embodiments, the second determination module includes: a time acquisition module, configured to obtain the request time for sending a time synchronization request and the response time for receiving the time synchronization information; a delay duration determination module, configured to determine the duration between the request time and the response time as the delay duration; and a third determination submodule, configured to determine the remaining duration after deducting the delay duration from the preset time interval duration base and the mean of the time offset as the time synchronization interval duration.
[0018] In some embodiments, the duration generation unit includes: a calibration module configured to, in response to detecting that the time synchronization interval duration is less than a preset minimum time interval duration, determine the preset minimum time interval duration as the calibrated time synchronization interval duration.
[0019] In some embodiments, the synchronization unit includes: a receiving module configured to receive a server time returned based on the time synchronization request in response to determining that the time synchronization request currently sent is the time synchronization request sent for the first time.
[0020] In some embodiments, the synchronization unit includes: a download duration acquisition module, configured to obtain the average download duration of the local system downloading data; an update module, configured to determine the server time based on the server system time indicated by the time synchronization information and the average download duration, and update the local system time to the server time.
[0021] According to the third aspect of the present disclosure, an embodiment of the present disclosure provides an electronic device, comprising: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by one or more processors, the one or more processors implement the time synchronization method provided in the first aspect.
[0022] According to a fourth aspect of the present disclosure, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the time synchronization method provided in the first aspect is implemented.
[0023] The time synchronization method and device provided by the present disclosure, when a time synchronization instruction is detected, executes the following time synchronization steps: sending a time synchronization request, and receiving time synchronization information for determining the server time based on the time synchronization request; updating the local system time to the server time according to the time synchronization information; then, generating the time synchronization interval duration based on the time offset between the read current time and the server time; and generating a time synchronization instruction when the time between the current time obtained from the local system and the execution of the above time synchronization steps is the time synchronization interval duration. The interval for time synchronization can be determined according to the time offset between the local system time and the server time, so as to avoid frequent time synchronization requests and reduce the waste of communication resources.
[0024] The technology according to the present application solves the problem of communication resource waste caused by frequent time synchronization.
[0025] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present application.
[0027] Figure 1 is an exemplary system architecture diagram to which embodiments of the present application may be applied;
[0028] Figure 2 is a flow chart of an embodiment of a time synchronization method according to the present application;
[0029] Figure 3 is a flowchart of another embodiment of the time synchronization method according to the present application;
[0030] Figure 4 is a structural diagram of an embodiment of a time synchronization device according to the present application;
[0031] Figure 5 It is a block diagram of an electronic device used to implement the time synchronization method of an embodiment of the present application. DETAILED DESCRIPTION
[0032] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0033] Figure 1 An exemplary system architecture 100 is shown to which an embodiment of the time synchronization method or time synchronization device of the present application can be applied.
[0034] like Figure 1 As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0035] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various client applications can be installed on terminal devices 101, 102, 103, such as shopping applications, financial applications, image applications, video applications, etc.
[0036] Terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting receiving server messages, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV), laptop computers, desktop computers, etc.
[0037] Terminal devices 101, 102, 103 can be hardware or software. When terminal devices 101, 102, 103 are hardware, they can be various electronic devices. When terminal devices 101, 102, 103 are software, they can be installed in the electronic devices listed above. They can be implemented as multiple software or software modules (for example, multiple software modules for providing distributed services), or they can be implemented as a single software or software module. No specific limitation is made here.
[0038] The terminal devices 101, 102, 103 can detect the time synchronization instruction, and when they detect the time synchronization instruction, they execute the time synchronization step: the terminal devices 101, 102, 103 send a time synchronization request to the server 105 through the network 104, and receive the time synchronization information returned by the server 105 based on the time synchronization request. The terminal devices 101, 102, 103 can update the time of the local system to the server time according to the time synchronization information. Afterwards, the terminal devices 101, 102, 103 can also generate a time synchronization interval duration based on the time offset between the current time read from the local system and the server time, and generate a time synchronization instruction once for each time synchronization interval duration, so that the terminal devices 101, 102, 103 perform time synchronization once for each time synchronization duration duration.
[0039] It should be noted that the time synchronization method provided in the embodiments of the present disclosure is generally executed by the terminal devices 101 , 102 , 103 , and accordingly, the time synchronization apparatus is generally provided in the terminal devices 101 , 102 , 103 .
[0040] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0041] Continue to refer Figure 2 , shows a process 200 of an embodiment of a time synchronization method according to the present disclosure, comprising the following steps:
[0042] Step 201, in response to detecting a time synchronization instruction, execute the following time synchronization steps: send a time synchronization request, wherein the time synchronization request includes the current time read from the local system; receive time synchronization information returned based on the time synchronization request for determining the server time; and update the local system time to the server time according to the time synchronization information.
[0043] In this embodiment, when the execution subject of the time synchronization method (for example Figure 1 When the terminal devices 101, 102, and 103 shown in the figure detect the time synchronization instruction, the time synchronization step is executed. The time synchronization instruction can be an instruction triggered by the user to synchronize the time of the terminal device, for example, an instruction for the terminal device to synchronize the time with the server is triggered when the user opens a shopping software / logs in to a shopping website and performs a coupon collection operation; the time synchronization instruction can also be an instruction sent by the server to control the terminal device to synchronize the time; the time synchronization instruction can also be an instruction generated by the terminal device at a fixed time period.
[0044] In this embodiment, the time synchronization step includes: the terminal device sends a time synchronization request to the server, wherein the time synchronization request may include the current time of the local system read by the terminal device in the local system. Then, the terminal device receives the time synchronization information returned by the server based on the time synchronization information, and the time synchronization information may include the current time of the server system, or the time difference between the server system and the local system of the terminal device, etc., which is used for the terminal device to determine the server time. Afterwards, the terminal device may update the time of the local system to the server time according to the time synchronization information, so that the time of the terminal device is consistent / synchronized with the time of the server system.
[0045] Step 202: Generate a time synchronization interval duration based on the time offset between the read current time and the server time.
[0046] In this embodiment, the terminal device can determine the duration between the current time read from the local system and the updated server time as the time offset, and generate a time synchronization interval duration based on the time offset, which is used as the period for the terminal device to perform the time synchronization step.
[0047] Step 203, obtaining the current time from the local system.
[0048] In this embodiment, the terminal device can continuously or intermittently obtain the current time from the local system, and the current time of the local system of the terminal device is obtained to determine whether the terminal device needs to perform the time synchronization step. For example, a preset time point for performing the time synchronization step can be preset, and if the current time obtained is the preset time point, the time synchronization step is performed.
[0049] Step 204 : In response to determining that the duration from the acquired current time to the time synchronization step is the time synchronization interval duration, a time synchronization instruction is generated.
[0050] In this embodiment, if the duration between the acquired current time and the time when the time synchronization step was most recently executed is the time synchronization interval duration, a time synchronization instruction is generated so that the terminal device executes the time synchronization step based on the time synchronization instruction.
[0051] The time synchronization method provided in this embodiment, when a time synchronization instruction is detected, executes the following time synchronization steps: sending a time synchronization request, and receiving time synchronization information for determining the server time returned based on the time synchronization request; updating the time of the local system to the server time according to the time synchronization information; then, generating the time synchronization interval duration based on the time offset between the read current time and the server time; and generating a time synchronization instruction when the time between the current time obtained from the local system and the execution of the above time synchronization steps is the time synchronization interval duration. The interval duration for time synchronization can be determined based on the time offset between the local system time and the server time, so as to avoid frequent time synchronization requests, reduce the waste of communication resources, and ensure the synchronization between the local system time and the server time.
[0052] Optionally, receiving time synchronization information indicating server time returned based on the time synchronization request includes: in response to determining that the currently sent time synchronization request is the first time sent time synchronization request, receiving the server time returned based on the time synchronization request.
[0053] In this embodiment, if it is determined that the time synchronization request currently sent is the first time synchronization request sent by the terminal device, the server returns the server time based on the time synchronization request, and the terminal device receives the server time. After determining that the terminal device is making a time synchronization request for the first time, this embodiment receives the server time returned by the server, thereby avoiding the problem of resource waste caused by the server needing to calculate the time difference between the terminal device and the server to return the time difference when the terminal device is used / powered on for the first time or has not been used for a long time, resulting in no local storage of time data / inaccurate stored time data.
[0054] Further references Figure 3 , shows a process 300 of another embodiment of the time synchronization method according to the present disclosure, comprising the following steps:
[0055] Step 301, in response to detecting a time synchronization instruction, execute the following time synchronization steps: send a time synchronization request, wherein the time synchronization request includes the current time read from the local system; receive time synchronization information returned based on the time synchronization request for determining the server time; and update the local system time to the server time according to the time synchronization information.
[0056] Step 302 , in response to determining that the time synchronization request currently sent is not the time synchronization request sent for the first time, obtaining a plurality of historical time offsets.
[0057] In this embodiment, if it is determined that the time synchronization request currently sent is not the first time synchronization request sent by the terminal device, multiple historical time offsets are obtained, wherein the historical time offset refers to: the time offset between the local time of the terminal device and the server system time determined based on the time synchronization request before the time synchronization request currently sent.
[0058] Step 303: Determine a time offset mean based on multiple historical time offsets.
[0059] In this embodiment, the time offset mean can be determined based on multiple historical time offsets. For example, the quotient of the sum of multiple historical time offsets and the number of multiple historical time offsets can be used as the time offset mean; or the median of multiple historical time offsets can be used as the time offset mean, etc.
[0060] Step 304: Use the difference between the mean value of the time offset and the preset time interval duration base as the time synchronization interval duration.
[0061] In this embodiment, a time interval duration base can be preset, and the remaining duration after deducting the average time offset from the preset time interval duration base can be used as the time synchronization interval duration; the remaining duration after deducting the average time offset of a preset proportion from the preset time interval duration base can also be used as the time synchronization interval duration.
[0062] Step 305, obtaining the current time from the local system.
[0063] Step 306: In response to determining that the duration from the current time to the time synchronization step is the time synchronization interval, generate a time synchronization instruction.
[0064] The description of step 301 , step 305 , and step 306 in this embodiment is consistent with the description of step 201 , step 203 , and step 204 , and will not be repeated here.
[0065] In this embodiment, the time synchronization interval for executing the time synchronization step is determined based on the average of multiple historical time offsets. The larger the average of the multiple historical time offsets, the shorter the time synchronization interval for executing the time synchronization step; the smaller the average of the multiple historical time offsets, the longer the time synchronization interval for executing the time synchronization step. This ensures that when the average of the multiple historical time offsets is larger, the time synchronization step is executed more frequently; and when the average of the multiple historical time offsets is smaller, the number of times the time synchronization step is executed is relatively small, thereby reducing the number of communications between the terminal device and the server while ensuring the accuracy of the terminal device time data.
[0066] Optionally, based on multiple historical time offsets, a mean time offset is determined, including: in response to detecting that the number of multiple historical time offsets is less than or equal to a preset number, arranging the multiple historical time offsets in ascending order to form a first array; determining the historical time offsets located in a first target sequence in the first array as the mean time offset, wherein the first target sequence is determined based on the number of historical time offsets.
[0067] In this embodiment, when it is detected that the number of multiple historical time offsets is less than or equal to a preset number, these multiple historical time offsets are arranged in ascending order to form a first array, and the historical time offset located at the first target position in the first array is determined as the average of these multiple historical time offsets (i.e., the time offset mean).
[0068] In this embodiment, the first target sequence is determined based on the number of multiple historical time offsets. For example, when there are 10 historical time offsets, the first target sequence may be 5 or 6 (i.e., the median position). For another example, the sequence parameter may be preset to 0.6 (or any other number greater than 0 and less than or equal to 1), and the product of the number of multiple historical time offsets and the preset sequence parameter may be rounded to an integer to serve as the first target sequence.
[0069] In this embodiment, the historical time offset at the first target bit sequence in the array formed by arranging multiple historical time offsets in ascending order is determined as the mean time offset, which can simplify the steps of determining the mean time offset and improve calculation efficiency.
[0070] Optionally, based on multiple historical time offsets, a mean time offset is determined, including: in response to detecting that the number of multiple historical time offsets is greater than a preset number, arranging the multiple historical time offsets determined based on the most recent preset number of time synchronization requests in ascending order to form a second array; determining the historical time offsets of a second target sequence in the second array as the mean time offset, wherein the second target sequence is determined based on the preset number.
[0071] In this embodiment, when it is detected that the number of multiple historical time offsets is greater than a preset number, the preset number of historical time offsets determined based on the most recent preset number of time synchronization requests are arranged in ascending order to form a second array, and the historical time offsets located in the second target sequence in the second array are used to determine the average of these multiple historical time offsets (i.e., the time offset mean).
[0072] In this embodiment, the second target bit sequence is determined based on a preset number. For example, the bit sequence parameter can be preset to 0.7 (or any other number greater than 0 and less than or equal to 1), and the product of the preset number and the preset bit sequence parameter is rounded to an integer to serve as the second target bit sequence. That is, if the preset number is 12, 12×0.7≈8 is used as the second target bit sequence.
[0073] In this embodiment, the historical time offset at the second target sequence in the array formed by arranging multiple historical time offsets in ascending order is determined as the mean time offset, which can simplify the steps of determining the mean time offset and improve calculation efficiency.
[0074] Optionally, the difference between a preset time interval duration base and a time offset mean is used as the time synchronization interval duration, including: obtaining the request time for sending a time synchronization request and the response time for receiving the time synchronization information; determining the duration between the request time and the response time as the delay duration; and determining the remaining duration after deducting the delay duration and the time offset mean from the preset time interval duration base as the time synchronization interval duration.
[0075] In this embodiment, the request time for sending the time synchronization request and the response time for receiving the time synchronization information returned by the server can be obtained; the duration between the request time and the response time is determined as the delay duration, and the remaining duration after deducting the delay duration and the average time offset from the preset time interval duration base is determined as the time synchronization interval duration.
[0076] Specifically, the time synchronization interval duration can be determined using the following formula (1):
[0077] M-(T2-T1)-αA (1)
[0078] Among them, M represents the preset time interval base, T1 represents the request time, T2 represents the response time, A represents the mean time offset, αA represents the mean time offset of the preset proportion, and α can be equal to 1 / N (N represents the number of times the terminal device has executed the time synchronization step).
[0079] When determining the length of the time synchronization interval, this embodiment uses the delay time determined based on the request time and the response time as a consideration for determining the length of the time synchronization interval. The frequency of executing the time synchronization step can be adjusted according to the length of the delay time, thereby reducing the number of communications between the terminal device and the server while ensuring the accuracy of the terminal device time data.
[0080] In the above combination Figure 2 and Figure 3In some optional implementations of the described embodiments, a time synchronization interval duration is generated based on the time offset between the read current time and the server time, including: in response to detecting that the time synchronization interval duration is less than a preset minimum time interval duration, determining the preset minimum time interval duration as the calibrated time synchronization interval duration.
[0081] In this embodiment, if it is detected that the determined time synchronization interval is less than the preset minimum time interval, the preset minimum time interval is determined as the calibrated time synchronization interval, and the time synchronization step is performed based on the calibrated time synchronization interval.
[0082] This embodiment can avoid the problem of system instability caused by the system frequently executing time synchronization requests due to the determined time synchronization interval being too short.
[0083] In the above combination Figure 2 and Figure 3 In some optional implementations of the described embodiments, the time of the local system is updated to the server time based on the time synchronization information, including: obtaining the average download time for the local system to download data; determining the server time based on the server system time indicated by the time synchronization information and the average download time, and updating the local system time to the server time.
[0084] In this embodiment, the average download time taken by the local system of the terminal device to download data can be obtained, and the server time can be determined based on the server system time indicated by the time synchronization information and the average download time taken. The time of the local system of the terminal device is then updated to the server time, so that the time of the local system of the terminal device is synchronized / consistent with the time of the server system.
[0085] Specifically, the terminal device can obtain the average download time of the local system downloading data from the local browser download information, and add the average download time to the server system time indicated by the received time synchronization information, and determine the sum of the time as the current server time, and then update the time of the local system of the terminal device to the current server time.
[0086] In this embodiment, when determining the current server time, the average download time consumed by the local system of the terminal device to download data is taken into consideration, which can improve the accuracy of determining the current server time.
[0087] Further references Figure 4 As an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of a device for extracting video clips. Figure 2 or Figure 3Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0088] like Figure 4 As shown, the apparatus 400 for extracting video segments of this embodiment includes: a synchronization unit 401, a duration generation unit 402, an acquisition unit 403, and an instruction generation unit 404. The synchronization unit 401 is configured to perform the following time synchronization steps in response to detecting a time synchronization instruction: sending a time synchronization request, wherein the time synchronization request includes the current time read from the local system; receiving time synchronization information for determining the server time returned based on the time synchronization request; updating the time of the local system to the server time according to the time synchronization information; the duration generation unit 402 is configured to generate the time synchronization interval duration based on the time offset between the read current time and the server time; and the acquisition unit 403 is configured to acquire the current time from the local system; the instruction generation unit 404 is configured to generate the time synchronization instruction in response to determining that the duration between the acquired current time and the execution of the time synchronization step is the time synchronization interval duration.
[0089] In some embodiments, the duration generation unit includes: an acquisition module, configured to acquire multiple historical time offsets in response to determining that a time synchronization request currently sent is not a time synchronization request sent for the first time; a first determination module, configured to determine a time offset mean based on multiple historical time offsets; and a second determination module, configured to use the difference between the time offset mean and a preset time interval duration base as the time synchronization interval duration.
[0090] In some embodiments, a first determination module includes: a first sorting module, configured to arrange multiple historical time offsets in ascending order to form a first array in response to detecting that the number of multiple historical time offsets is less than or equal to a preset number; a first determination submodule, configured to determine the historical time offsets located in a first target sequence in the first array as the mean of the time offsets, wherein the first target sequence is determined based on the number of historical time offsets.
[0091] In some embodiments, a first determination module includes: a second sorting module, configured to, in response to detecting that the number of multiple historical time offsets is greater than a preset number, arrange the multiple historical time offsets determined based on the most recent preset number of time synchronization requests in ascending order to form a second array; a second determination submodule, configured to determine the historical time offsets of a second target sequence in the second array as the mean of the time offsets, wherein the second target sequence is determined based on the preset number.
[0092] In some embodiments, the second determination module includes: a time acquisition module, configured to obtain the request time for sending a time synchronization request and the response time for receiving the time synchronization information; a delay duration determination module, configured to determine the duration between the request time and the response time as the delay duration; and a third determination submodule, configured to determine the remaining duration after deducting the delay duration from the preset time interval duration base and the mean of the time offset as the time synchronization interval duration.
[0093] In some embodiments, the duration generation unit includes: a calibration module configured to, in response to detecting that the time synchronization interval duration is less than a preset minimum time interval duration, determine the preset minimum time interval duration as the calibrated time synchronization interval duration.
[0094] In some embodiments, the synchronization unit includes: a receiving module configured to receive a server time returned based on the time synchronization request in response to determining that the time synchronization request currently sent is the time synchronization request sent for the first time.
[0095] In some embodiments, the synchronization unit includes: a download duration acquisition module, configured to obtain the average download duration of the local system downloading data; an update module, configured to determine the server time based on the server system time indicated by the time synchronization information and the average download duration, and update the local system time to the server time.
[0096] Each unit in the above device 400 is similar to the reference Figure 2 or Figure 3 Therefore, the operations, features and technical effects described above for the method for extracting video clips are also applicable to the device 400 and the units included therein, and will not be described in detail here.
[0097] According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.
[0098] like Figure 5 , is a block diagram of an electronic device 500 for extracting a video clip according to an embodiment of the present application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.
[0099] like Figure 5 As shown, the electronic device includes: one or more processors 501, a memory 502, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are interconnected using different buses and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the electronic device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In other embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple electronic devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 5 A processor 501 is taken as an example.
[0100] The memory 502 is a non-transitory computer-readable storage medium provided in the present application. The memory stores instructions executable by at least one processor to enable the at least one processor to perform the method for extracting video segments provided in the present application. The non-transitory computer-readable storage medium of the present application stores computer instructions, which are used to enable a computer to perform the method for extracting video segments provided in the present application.
[0101] The memory 502 is a non-transient computer-readable storage medium that can be used to store non-transient software programs, non-transient computer executable programs and modules, such as program instructions / modules corresponding to the method for extracting video clips in the embodiment of the present application (for example, the attached Figure 4 The processor 501 executes various functional applications and data processing of the server by running the non-transient software programs, instructions and modules stored in the memory 502, that is, the method for extracting video clips in the above method embodiment is implemented.
[0102] The memory 502 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required by at least one function; the data storage area may store data created according to the use of the electronic device for extracting video clips, etc. In addition, the memory 502 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory 502 may optionally include a memory remotely arranged relative to the processor 501, and these remote memories may be connected to the electronic device for extracting video clips via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0103] The electronic device for extracting a video clip may further include: an input device 503, an output device 504, and a bus 505. The processor 501, the memory 502, the input device 503, and the output device 504 may be connected via the bus 505 or in other ways. Figure 5 The connection via bus 505 is taken as an example.
[0104] The input device 503 can receive input digital or character information, and generate key signal input related to user settings and function control of the electronic device for extracting video clips, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator rod, one or more mouse buttons, a trackball, a joystick, and other input devices. The output device 504 may include a display device, an auxiliary lighting device (e.g., an LED), and a tactile feedback device (e.g., a vibration motor). The display device may include, but is not limited to, a liquid crystal display (LCD), a light emitting diode (LED) display, and a plasma display. In some embodiments, the display device may be a touch screen.
[0105] Various implementations of the systems and techniques described herein can be realized in digital electronic circuit systems, integrated circuit systems, dedicated ASICs (application specific integrated circuits), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0106] These computer programs (also referred to as programs, software, software applications, or code) include machine instructions for programmable processors and can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or means (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0107] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0108] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0109] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.
[0110] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here.
[0111] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.
Claims
1. A time synchronization method, comprising: In response to detecting the time synchronization instruction, the following time synchronization steps are performed: sending a time synchronization request, wherein the time synchronization request includes the current time read from the local system; receiving time synchronization information for determining the server time returned based on the time synchronization request; updating the time of the local system to the server time according to the time synchronization information; Based on the time offset between the read current time and the server time, a time synchronization interval duration is generated, including: in response to determining that the time synchronization request currently sent is not the time synchronization request sent for the first time, a plurality of historical time offsets are obtained; based on the plurality of historical time offsets, a mean time offset is determined; a request time for sending the time synchronization request and a response time for receiving the time synchronization information are obtained; the duration between the request time and the response time is determined as a delay duration; the remaining duration after deducting the delay duration and the mean time offset from a preset time interval duration base is determined as the time synchronization interval duration; and Get the current time from the local system; In response to determining that the duration from the acquired current time to executing the time synchronization step is the time synchronization interval duration, the time synchronization instruction is generated.
2. The method according to claim 1, wherein: The determining the time offset mean based on the multiple historical time offsets includes: In response to detecting that the number of the plurality of historical time offsets is less than or equal to a preset number, arranging the plurality of historical time offsets in ascending order to form a first array; The historical time offsets of a first target sequence in the first array are determined as the time offset mean, wherein the first target sequence is determined based on the number of the historical time offsets.
3. The method according to claim 1, wherein: The determining the time offset mean based on the multiple historical time offsets includes: In response to detecting that the number of the plurality of historical time offsets is greater than a preset number, arranging the plurality of historical time offsets determined based on the most recent preset number of time synchronization requests in ascending order to form a second array; The historical time offset of a second target sequence in the second array is determined as the time offset mean, wherein the second target sequence is determined based on the preset number.
4. The method according to claim 1, wherein: The step of generating a time synchronization interval duration based on the time offset between the read current time and the server time includes: In response to detecting that the time synchronization interval duration is less than a preset minimum time interval duration, the preset minimum time interval duration is determined as the calibrated time synchronization interval duration.
5. The method according to claim 1, wherein: The receiving time synchronization information returned based on the time synchronization request and used to indicate the server time includes: In response to determining that the time synchronization request currently sent is the time synchronization request sent for the first time, receiving a server time returned based on the time synchronization request.
6. The method according to any one of claims 1 to 5, wherein: The updating of the local system time to the server time according to the time synchronization information includes: Get the average download time of the local system download data; The server time is determined according to the server system time indicated by the time synchronization information and the average downloading time, and the local system time is updated to be the server time.
7. A time synchronization device, comprising: The synchronization unit is configured to perform the following time synchronization steps in response to detecting a time synchronization instruction: sending a time synchronization request, wherein the time synchronization request includes a current time read from a local system; receiving time synchronization information for determining a server time returned based on the time synchronization request; and updating the time of the local system to the server time according to the time synchronization information; A duration generation unit is configured to generate a time synchronization interval duration based on the time offset between the read current time and the server time, the duration generation unit includes an acquisition module, a first determination module and a second determination module, wherein the acquisition module is configured to acquire multiple historical time offsets in response to determining that the time synchronization request currently sent is not the time synchronization request sent for the first time; the first determination module is configured to determine the time offset mean based on the multiple historical time offsets, the second determination module includes a time acquisition module, a delay duration determination module and a third determination submodule, the time acquisition module is configured to acquire the request time of sending the time synchronization request and the response time of receiving the time synchronization information, the delay duration determination module is configured to determine the duration between the request time and the response time as the delay duration, and the third determination submodule is configured to determine the remaining duration after deducting the delay duration and the time offset mean from the preset time interval duration base as the time synchronization interval duration; and An acquisition unit, configured to acquire current time from a local system; The instruction generating unit is configured to generate the time synchronization instruction in response to determining that the duration from the acquired current time to the execution of the time synchronization step is the time synchronization interval duration.
8. The device according to claim 7, wherein: The first determining module includes: A first sorting module is configured to, in response to detecting that the number of the plurality of historical time offsets is less than or equal to a preset number, arrange the plurality of historical time offsets in ascending order to form a first array; The first determination submodule is configured to determine the historical time offset of the first target sequence in the first array as the mean of the time offsets, wherein the first target sequence is determined based on the number of the historical time offsets.
9. The device according to claim 7, wherein: The first determining module includes: A second sorting module is configured to, in response to detecting that the number of the plurality of historical time offsets is greater than a preset number, arrange the plurality of historical time offsets determined based on the most recent preset number of time synchronization requests in ascending order to form a second array; The second determination submodule is configured to determine the historical time offset of the second target sequence in the second array as the time offset mean, wherein the second target sequence is determined based on the preset number.
10. The device according to claim 7, wherein: The duration generating unit comprises: The calibration module is configured to, in response to detecting that the time synchronization interval duration is less than a preset minimum time interval duration, determine the preset minimum time interval duration as the time synchronization interval duration after calibration.
11. The device according to claim 7, wherein: The synchronization unit comprises: The receiving module is configured to receive the server time returned based on the time synchronization request in response to determining that the time synchronization request currently sent is the time synchronization request sent for the first time.
12. The device according to any one of claims 7 to 11, wherein: The synchronization unit comprises: A download duration acquisition module is configured to acquire an average download duration of the local system download data; The update module is configured to determine the server time according to the server system time indicated by the time synchronization information and the average downloading time, and update the local system time to the server time.
13. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 6.
14. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Clock synchronous control method, device and system based on SNTP
CN104202204A
Method and device for correcting time information
CN110662284A