私はそれ自身でうまく動作するストップウォッチコードを持っています。私は開始し、ユーザーがパンチアウトしたときにそれを表示しようとしているので、時間が計算され、ユーザーがパンチアウトすると停止します。私はそのデータを使ってデータベースに挿入したいと思っています。それをどうやってやりますか?データをデータベースに挿入した後にストップウォッチを始めるには?
<?php if($timedata['is_clocked_in'] === 'Yes'):?>
<h5 style="text-transform: uppercase" class="alert alert-info col-md-4">You Are Clocked In : (time count) </h5>
<?php elseif($timedata['is_clocked_in'] === 'No'):?>
<button><i class="fa fa-plus" aria-hidden="true"></i> Punch In Now</button>
<?php endif;?>
マークアップ
<h1><time>00:00:00</time></h1>
<button id="start">start</button>
<button id="stop">stop</button>
<button id="clear">clear</button>
スクリプト
var h1 = document.getElementsByTagName('h1')[0],
start = document.getElementById('start'),
stop = document.getElementById('stop'),
clear = document.getElementById('clear'),
seconds = 0, minutes = 0, hours = 0,
t;
function add() {
seconds++;
if (seconds >= 60) {
seconds = 0;
minutes++;
if (minutes >= 60) {
minutes = 0;
hours++;
}
}
h1.textContent = (hours ? (hours > 9 ? hours : "0" + hours) : "00") + ":" + (minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") + ":" + (seconds > 9 ? seconds : "0" + seconds);
timer();
}
function timer() {
t = setTimeout(add, 1000);
}
timer();
/* Start button */
start.onclick = timer;
/* Stop button */
stop.onclick = function() {
clearTimeout(t);
}
/* Clear button */
clear.onclick = function() {
h1.textContent = "00:00:00";
seconds = 0; minutes = 0; hours = 0;
}
おかげで本当に 'live'ソリューションではありません...プラスPHPの時間がローカルになることはありません...私は右ので、そのための完全なクラスを書くために私を必要とするそれを得るために、タイムゾーンを設定する必要があります私は何か国際的なものを造ります –
あなたは絶対時間ではなく、渡された時間だけが必要なので、現地時間は必要ありません。 –
あなたは何かのスニペットを共有することによってあなたが話していることを見せてもらえますか? –