In the foreground page development usually use to calculate two time difference, first attach the implementation method
[JavaScript]View PlainCopy
- End time
- End_str = ("2014-01-01 10:15:00"). Replace (/-/g,"/"); Generally get the format of the time is: Yyyy-mm-dd hh24:mi:ss, so I use this as an example, is the format, you do not have to replace.
- var end_date = new Date (END_STR); Convert a string to a time
- Start time
- Sta_str = ("2014-01-01 10:15:00"). Replace (/-/g,"/");
- var sta_date = new Date (STA_STR);
- var num = (end_date-sta_date)/(1000*3600*24); //Find out the time difference between two times, this is the number of days
- var days = parseint (Math.ceil (num)); //Convert to full day (less than 0 of the play does not have to turn)
- The following is attached to the JS in some of the methods for Time class operation
- var mydate = new Date ();
- Mydate.getyear (); //Get Current year (2-bit)
- Mydate.getfullyear (); //Get the full year (4-bit, 1970-????)
- Mydate.getmonth (); //Get the current month (0-11, 0 for January)
- Mydate.getdate (); //Get current day (1-31)
- Mydate.getday (); //Get Current week x (0-6, 0 for Sunday)
- Mydate.gettime (); //Gets the current time (number of milliseconds since 1970.1.1)
- Mydate.gethours (); //Get current hours (0-23)
- Mydate.getminutes (); //Gets the current number of minutes (0-59)
- Mydate.getseconds (); //Gets the current number of seconds (0-59)
- Mydate.getmilliseconds (); //Gets the current number of milliseconds (0-999)
- Mydate.tolocaledatestring (); //Get the current date
- var mytime=mydate.tolocaletimestring (); //Get current time
- Mydate.tolocalestring (); //Get date and time----if it involves a minute or seconds, use it directly.
How to convert a string to a time in JS and calculate the difference