因此,我有两个日期<代码>。 缩略语
我怎么能发现它们之间有多少次?
因此,我有两个日期<代码>。 缩略语
我怎么能发现它们之间有多少次?
I m 计及YYYY & ZZZZZZZ系指年、MM &等值的惯性价值;NN系指年月和DD &值;EE作为惯性值,即月日。
var t1 = new Date(YYYY, MM, DD, 0, 0, 0, 0);
var t2 = new Date(ZZZZ, NN, EE, 0, 0, 0, 0);
var dif = t1.getTime() - t2.getTime();
var Seconds_from_T1_to_T2 = dif / 1000;
var Seconds_Between_Dates = Math.abs(Seconds_from_T1_to_T2);
或者,如果你的日期以javascript格式出现,那么你可以 par。
var dif = Date.parse(MM + " " + DD + ", " + YYYY) - Date.parse(NN + " " + EE + ", " + ZZZZ);
并且,你可以把这一价值作为微秒的区别(如果我的两个例子都具有同样的含义)
简略:
var a = new Date();
alert("Wait a few seconds, then click OK");
var b = new Date();
var difference = (b - a) / 1000;
console.log("You waited: " + difference + " seconds");
你们只能这样做。
var secondBetweenTwoDate = Math.abs((new Date().getTime() - oldDate.getTime()) / 1000);
var a = new Date("2010 jan 10"),
b = new Date("2010 jan 9");
alert(
a + "
" +
b + "
" +
"Difference: " + ((+a - +b) / 1000)
);
2. 便利的方式:
function diff_hours(dt2, dt1)
{
var diff =(dt2.getTime() - dt1.getTime()) / 1000;
diff /= (60 * 60);
return Math.abs(Math.round(diff));
}
function diff_minutes(dt2, dt1)
{
var diff =(dt2.getTime() - dt1.getTime()) / 1000;
diff /= (60);
return Math.abs(Math.round(diff));
}
function diff_seconds(dt2, dt1)
{
var diff =(dt2.getTime() - dt1.getTime()) / 1000;
return Math.abs(Math.round(diff));
}
function diff_miliseconds(dt2, dt1)
{
var diff =(dt2.getTime() - dt1.getTime());
return Math.abs(Math.round(diff));
}
dt1 = new Date(2014,10,2);
dt2 = new Date(2014,10,3);
console.log(diff_hours(dt1, dt2));
dt1 = new Date("October 13, 2014 08:11:00");
dt2 = new Date("October 14, 2014 11:13:00");
console.log(diff_hours(dt1, dt2));
console.log(diff_minutes(dt1, dt2));
console.log(diff_seconds(dt1, dt2));
console.log(diff_miliseconds(dt1, dt2));
function parseDate(str) {
const [dateStr, timeStr] = str.split( );
const [m,d,y] = dateStr.split( / );
const [h,min] = timeStr.split( : );
const date = new Date(y,m,d,h,min,0, 0);
return date;
}
const date1 = parseDate( 28/6/2022 22:55 );
const date2 = parseDate( 28/6/2022 22:58 );
const diffInSeconds = (date2 - date1) / 1000;
console.log(diffInSeconds)
I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...
So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...
I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?
I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...
Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...
I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...
I m trying to parse timestamp strings like "Sat, 11/01/09 8:00PM EST" in Python, but I m having trouble finding a solution that will handle the abbreviated timezone. I m using dateutil s parse() ...
I love the new DATE datatype in SQL Server 2008, but when I compare a DATE field to a DATETIME field on a linked server (SQL 2005, in this case), like this: DECLARE @MyDate DATE SET @MyDate = CONVERT(...