起始点的时间表计算JQuery/Ajax/其他



我需要为时间创建一堆前端计算。我搜索了又搜索,似乎找不到任何好的教程或模板,让我指向正确的方向。我想知道是否有人可以这样做,关于以下链接:

https://crm.champ.net/timesheet-static

所以这就是我需要帮助来完成的事情。当用户输入时间&然后暂停(然后时间在2 & &;2),我需要计算出当天的总正常时间。

我已经得到了所有的后端PHP/MySQL的东西覆盖一旦我可以得到的值填充,但我假设这是Ajax或JQuery,我在这里寻找,我不知道如何做到这一点。有什么想法或链接到有人已经做到了吗?

在本例中,我们从日期字符串中创建一个DateTime,如"08/18/2014 05:30:PM"。

从该页中,这是一个从那里的两个字段获取适当日期时间的示例。var time = new Date($('#fdate1').val() +" "+ $('#fti2-1').val())。Fdate1包含日期引用,fti2-2包含时间引用。

你可以使用内置在JS中的DateTime函数。
参考:http://www.w3schools.com/jsref/jsref_obj_date.asp

注意事项:

. gettime()函数用于返回从1970年1月1日午夜开始的毫秒数。你可以用它来得到两个日期的差值。

. getdate()将在DateTime中返回当前月份的日期。

. setdate()将根据DateTime中的当前月份设置日期(示例如下)。传入一个负数或一个超过当前DateTime中的月份的天数的数字,将根据溢出的天数将DateTime提前到下一个具有正确天数的月份。

同样的逻辑可以应用于分、秒等。

例子:

function differenceInMinutes(timeIn, timeOut) {
  return (timeOut.getTime() - timeIn.getTime()) / 1000 / 60;
  //1000 ms per sec. 60 sec per min
}
function twoWeeksAgo() {
  //gets new DateTime set to current time
  var date = new Date();
  //We get the current day of the month (at time of this post it will return 19).
  //Subtract 14 from that and set that to the current day.
  date.setDate(date.getDate() - 14);
  return date;
  //A value causing the date to be less then 0 (in this case 20 or greater) will cause the date to push back the the last month.
}

最新更新