Javascript 获取当前时间并插入数据库
我是发展科的新手。我开发了一个代码,通过提供暂停/恢复选项来插入员工的时间。 我一直面临的问题是,我只能检索页面开始时间和之后的第一次暂停,而恢复时间是显示页面开始时间,但我需要恢复时间。 例如:页面开始时间为1430389269247 页面暂停时间为1430389301723 页面恢复时间为1430389314550 当我再次暂停时,时间必须从恢复时间1430389314550开始。 但我只能得到1430389269247的开始时间Javascript 获取当前时间并插入数据库,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我是发展科的新手。我开发了一个代码,通过提供暂停/恢复选项来插入员工的时间。 我一直面临的问题是,我只能检索页面开始时间和之后的第一次暂停,而恢复时间是显示页面开始时间,但我需要恢复时间。 例如:页面开始时间为1430389269247 页面暂停时间为1430389301723 页面恢复时间为1430389314550 当我再次暂停时,时间必须从恢复时间1430389314550开始。 但我只能得到1430389269247的开始时间 $(document).read
$(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');
}
});
在您的第一次UrlToPass中,您将startTime替换resumedTime。尽管我不能完全确定,但我认为这就是代码不起作用的原因。在任何情况下,您都不应该通过URL传递当前时间的时间戳,而应该使用数据库本身为此提供的SQL函数…(您应该使用更合适的数据类型,而不是存储整数时间戳——对于MySQL f.e.,其中之一:)