3 回答
12345678_0001
TA贡献1802条经验 获得超5个赞
var a = new Date(); // Current date now.var b = new Date(2010, 0, 1, 0, 0, 0, 0); // Start of 2010.var d = (b-a); // Difference in milliseconds.
var seconds = parseInt((b-a)/1000);
minutes
seconds
hours
minutes
function get_whole_values(base_value, time_fractions) { time_data = [base_value]; for (i = 0; i < time_fractions.length; i++) { time_data.push(parseInt(time_data[i]/time_fractions[i])); time_data[i] = time_data[i] % time_fractions[i]; }; return time_data;};// Input parameters below: base value of 72000 milliseconds, time fractions are// 1000 (amount of milliseconds in a second) and 60 (amount of seconds in a minute). console.log(get_whole_values(72000, [1000, 60]));// -> [0,12,1] # 0 whole milliseconds, 12 whole seconds, 1 whole minute.
new Date(<year>, <month>, <day>, <hours>, <minutes>, <seconds>, <milliseconds>);
慕村225694
TA贡献1880条经验 获得超4个赞
计算两个已知日期之间的差额
Date.daysBetween = function( date1, date2 ) { //Get 1 day in milliseconds var one_day=1000*60*60*24; // Convert both dates to milliseconds var date1_ms = date1.getTime(); var date2_ms = date2.getTime(); // Calculate the difference in milliseconds var difference_ms = date2_ms - date1_ms; // Convert back to days and return return Math.round(difference_ms/one_day); }//Set the two datesvar y2k = new Date(2000, 0, 1); var Jan1st2010 = new Date(y2k.getFullYear() + 10, y2k.getMonth(), y2k.getDate());var today= new Date();//displays 726console.log( 'Days since ' + Jan1st2010.toLocaleDateString() + ': ' + Date.daysBetween(Jan1st2010, today));
白衣非少年
TA贡献1155条经验 获得超0个赞
// This is for first date first = new Date(2010, 03, 08, 15, 30, 10); // Get the first date epoch object document.write((first.getTime())/1000); // get the actual epoch values second = new Date(2012, 03, 08, 15, 30, 10); // Get the first date epoch object document.write((second.getTime())/1000); // get the actual epoch values diff= second - first ; one_day_epoch = 24*60*60 ; // calculating one epoch if ( diff/ one_day_epoch > 365 ) // check , is it exceei { alert( 'date is exceeding one year'); }
添加回答
举报
0/150
提交
取消