Javascript compares the days between two dates and the javascript days

Source: Internet
Author: User
Tags date1

Javascript compares the days between two dates and the javascript days


$ (Function (){
Var starttime = transdate ("15:53:00 ");
Var endtime = transdate ("15:53:00 ");

Var now = "'" + new Date (). getTime () + "'";
Var nowtime = now. substr (1, 10 );

If (nowtime> endtime ){
('.Meeting_time'{.html ('exhibition ended ');
} Else if (nowtime <starttime ){
Var day = get_date_different (nowtime, starttime );
('.Meeting_time'0000.html ('from the start of the exhibition, '+ day + 'day ');
} Else {
('.Meeting_time'0000.html ('exhibition in progress ');
}
});
Function get _ (www.111cn.net) date_different (date_1, date_2 ){
Var days = date_2-date_1;
Var time = parseInt (days/(60*60*24 ));
Return time;
}
Function transdate (endTime ){
Var date = new Date ();
Date. setFullYear (endTime. substring (0, 4 ));
Date. setMonth (endTime. substring (5, 7)-1 );
Date. setDate (endTime. substring (8, 10 ));
Date. setHours (endTime. substring (11,13 ));
Date. setMinutes (endTime. substring (14,16 ));
Date. setSeconds (endTime. substring (17,19 ));
Return Date. parse (date)/1000;
} From: http://www.111cn.net/wy/js-ajax/66437.htm
The difference between two javascript dates is several months.

Month1 = parseInt (date1.split ("-") [0], 10) * 12 + parseInt (date1.split ("-") [1], 10); // note that the Delimiter is-
Month1 = parseInt (date2.split ("-") [0], 10) * 12 + parseInt (date2.split ("-") [1], 10 );
Month1-month2.
Difficulties:
Date2.split ("-") [0] is to split date2 into three arrays through the separator "-", and take the first one, that is, the number of years
ParseInt (number, 10) is a number that converts a string to a decimal place.

Compare the different days of two dates

Compare the different days of two dates
Response. write DateDiff ("d", Date (), "01-07,07 ")
Date () Today's date

DateDiff Function

Returns the value of Variant (Long), indicating the number of time intervals between two specified days.

Syntax

DateDiff (interval, date1, date2 [, firstdayofweek] [, firstweekofyear])

The DateDiff function syntax contains the following naming parameters:

Partial description
Interval is required. String expression used to calculate the time difference between date1 and date2
Date1 □date2 is required; Variant (Date ). The two dates used in the calculation.
Firstdayofweek is optional. Specifies the constant of the first day of a week. If not specified, Sunday is the first day.
Firstweekofyear is optional. Specifies the constant of the first week of a year. If this parameter is not specified, the week that contains April 1 is the first week.

Set

The interval parameter settings are as follows:

Set description
Yyyy
Q quarter
M month
Y number of days in a year
D
Number of days per week
Ww week
H hour
N minutes
S seconds

The firstdayofweek parameter is set as follows:

Constant Value description
VbUseSystem 0 is set using nls api.
VbSunday 1 Sunday (default)
VbMonday 2 Monday
VbTuesday 3 Tuesday
VbWednesday 4
VbThursday 5 Thursday
VbFriday 6 Friday
VbSaturday 7 Saturday

Constant Value description
VbUseSystem 0 is set using nls api.
VbFirstJan1 1 starts from the week of July 1, January 1 (default ).
VbFirstFourDays 2 starts from the first half of its week in the week of the New Year.
VbFirstFullWeek 3 starts from the week of the first non-Cross-Year Plan.

Description

The DateDiff function can be used to determine the specified time interval between two dates. For example, you can use DateDiff to calculate the number of days between two dates, or calculate the number of weeks from today to the end of the year.

To calculate the number of days in which date1 differs from date2, you can use "day of the year" (y) or "day" (d ). When interval is "the number of days in a week" (w), DateDiff returns the number of weeks in the two-day period. If date1 is Monday, DateDiff calculates the number of Monday until date2. This number contains date2 but not date1. However, if interval is "Week" (ww), The DateDiff function returns the "calendar week" number for the two-day period. Calculated based on the number of Sundays between date1 and date2. If date2 is just Sunday, date2 will also be added to the DateDiff counting result. However, no matter whether date1 is Sunday or not, it will not be included.

If date1 is later than date2, the return value of the DateDiff function is negative.

The firstdayofweek parameter affects the calculation result using the time interval symbol "W" or "WW.

If date1 or date2 is a date text, the specified year becomes a fixed part of the date. However, if date1 or date2 is enclosed in double quotation marks... the remaining full text>

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.