English 中文(简体)
如何计算时间差?
原标题:How to calculate the time difference?

如何计算时间差 。 我既有服务器的时间, 也有客户系统的时间 : isoDate date date 日期格式。 以下是我拥有的输出数据 :

UTC 中的服务器时间转换为本地音节时区时间 :

Tue 2012年5月22日 14:29:51 GMT+0530(印度标准时间)

本地系统时间 :

Tue 2012年5月22日 14:31:51 GMT+0530(印度标准时间)

如果本地系统时间少于或大于时间,我想进行计算的方式是,如果本地系统时间少于或大于时间,那么说5分钟(可配置值),忽略与服务器时间显示的要执行其它任务的时间之间的秒差。我不知道如何进行计算,因为当时间是午夜12:01时,根据服务器的时间,然后是日期、小时和分钟的变化,而如果本地系统仅落后4分钟,如何确定差数不少于5分钟,尽管日期已经改变。我的主要想法是检查所有内容,以匹配日期、时间和时间,并检查差数。请帮助。

最佳回答
function getDateDiff(date1, date2) {
    var second = 1000,
    minute = second * 60,
    date1 = new Date(date1).getTime();
    date2 = (date2 ==  now ) ? new Date().getTime() : new Date(date2).getTime(); // now means current date
    var timediff = date2 - date1;
    if (isNaN(timediff)) return NaN;
    return Math.flo或(timediff / minute);
}

<强 > 使用:

getDateDiff(YOUR_SERVER_DATE, YOUR_CLIENT_DATE); // output will be in unit minute

getDateDiff(YOUR_SERVER_DATE,  now ); // f或 current date 
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签