On the Sina Weibo homepage, you can see that the time displayed after each microblog is not in the standard year-month-day format, but the time difference after conversion, for example: published five minutes ago and two hours ago, similar functions
On the Sina Weibo homepage, you can see that the time displayed after each microblog is not in the standard year-month-day format, but the time difference after conversion, for example: posted 5 minutes ago and 2 hours ago, it looks more intuitive
Share the sample code for calculating the time difference in javascript and the sample code in javascript.
In practical applications, the gap between two time points needs to be calculated. Generally, the gap between the current time and a specified
To achieve similar functions, using JS can be implemented as follows:
One, JavaScript function implementation:Example 1:
Copy Code code as follows:
JavaScript functions:
var minute = 1000 * 60;
var hour = minute * 60;
var day = hour *
Two hours ago
When you evaluate the time period control on the Interface today, you must obtain the current time and the time two hours before the current time. How can we implement it in JavaScript?
The new date () in javascript can get the
To implement similar functions, use JS as follows:
I. javascript function implementation:Instance 1:Copy codeThe Code is as follows:// JavaScript Functions:Var minute = 1000*60;Var hour = minute * 60;Var day = hour * 24;Var halfamonth = day * 15;Var
on Sina Weibo homepage see the time shown behind each Weibo is not the standard year-month-day format, instead, the time difference between the conversion, such as: Published 5 minutes ago, published in "2 hours ago", compared to the standard
Javascript date subtraction, time difference, and javascript Time Difference// Calculate the time differenceVar from_date = new Date (from_time );Var end_date = new Date (end_time );Var time_different = (end_date-from_date)/86400000; // that is, 24*6
The time in Javascript will inevitably deal with time when programming. For example, to complete a second kill, it involves time access, time synchronization, time difference calculation, and many other details. A simple example of JavsScript. When
The JS implementation calculates a time difference of two times:In practice, it is necessary to calculate the gap between the two time points, which is generally the difference between the current time and a specified point in time, and sometimes it
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.