时间表计算的起点JQuery / Ajax / other

时间:2014-08-19 19:36:48

标签: javascript jquery ajax

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

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

所以这就是我需要帮助才能完成的事情。 当用户输入时间&和超时(然后是时间2和时间2),我需要计算当天的正常总时数。

一旦我可以获得填充的值,我已经获得了所有后端的PHP / MySQL内容,但我认为它是我在这里寻找的Ajax或JQuery而且我没有&# 39;不知道怎么做。任何想法或链接到已经完成它的人?

1 个答案:

答案 0 :(得分:0)

在这种情况下,我们从日期字符串中创建一个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.
}