【问题标题】:fetching the current time and insert into database获取当前时间并插入数据库
【发布时间】:2015-04-30 19:50:22
【问题描述】:

我是开发部门的新手。我开发了一个代码,通过提供暂停/恢复选项来插入员工的时间。 我一直面临的问题是我只能检索页面开始时间并在此之后第一次暂停,而恢复时间正在显示页面开始时间,但我需要恢复时间。 例如:页面开始时间是 1430389269247 页面暂停时间为 1430389301723 页面恢复时间为 1430389314550 当我再次暂停时,时间必须从恢复时间 1430389314550 开始。 但相反,我只能得到开始时间 1430389269247。

              $(document).ready(function()
{
var startTime = Date.now();
var pausedTime;
alert(""+startTime);
$('#btn_pause_resume').click(function () {
if ($(this).data('paused')==='false') 
{
//alert('Resumed...');
//$(this).data('paused', 'true');
resumedTime = Date.now();
var UrlToPass = 'action=pauseTime&pausedTime='+pausedTime+'&resumedTime='+startTime;
$.ajax({ // Send the credential values to another checker.php using Ajax in POST menthod
type : 'POST',
data : UrlToPass,
url  : 'pauseTimer.php',
success: function(responseText){ // Get the result and asign to each cases
if(responseText == 0){
//  window.location = 'index.html';
}
else if(responseText == 1){
         alert("Sucess");
//window.location = 'majorprocess.php';
}
else{
alert('Problem with sql query');
}
}
});
         } else {
         pausedTime = Date.now();
         alert('Paused...');
         //   alert(""+pausedTime);
          var UrlToPass = 'action=workTime&startTime='+startTime+'&pausedTime='+pausedTime;
$.ajax({ // Send the credential values to another checker.php using Ajax in POST menthod
type : 'POST',
data : UrlToPass,
url  : 'workedTimer.php',
success: function(responseText){ // Get the result and asign to each cases
if(responseText == 0){
//  window.location = 'index.html';
}
else if(responseText == 1){
          alert("Sucess");
//window.location = 'majorprocess.php';
}
else{
alert('Problem with sql query');
}
}
});
          $(this).data('paused', 'false');
    }
});     

【问题讨论】:

  • 在任何情况下,您都不应该通过 URL 传递当前时间的时间戳,而只需使用数据库本身提供的 SQL 函数……(并且您应该使用更合适的数据类型,而不是存储整数时间戳 - 对于 MySQL f.e.,其中之一:dev.mysql.com/doc/refman/5.5/en/date-and-time-types.html)

标签: javascript php jquery html


【解决方案1】:

在您的第一个 UrlToPass 中,您将 startTime 代替 resumedTime。虽然我不完全确定,但我认为这就是您的代码无法正常工作的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2013-03-06
    • 2019-01-03
    • 2019-04-19
    • 2023-04-05
    • 2017-05-16
    • 1970-01-01
    相关资源
    最近更新 更多