我正在进行ajax调用,例如返回40:12:59的字符串。 该字符串带有已包裹的td。
我如何开始计算从那里开始的秒数?
我还可以返回完整的时间戳(例如1564061259) 然后从那里开始工作。但最后,我需要像上面指定的日期格式。
我要显示数据的页面上的Ajax调用:
<div id="result"></div>
<script>
function load_data()
{
$.ajax({
url:"_overview.php",
method:"POST",
success:function(data)
{
$('#result').html(data);
},
complete: function(){
$('#loading-image').hide();
}
});
}
load_data()
</script>
检查最后7行。这是我打算在前端每秒增加一的值。 该文件(“ _overview.php”)是发出请求的文件。
<?php
include '../../variables.php';
include '../../_Database.php';
$db = Database::getInstance();
echo ' <table class="table" style="zoom: 1;">';
echo ' <thead class="thead-dark">';
echo ' <tr>';
echo ' <th scope="col">Auftrag</th>';
echo ' <th scope="col">Artikel</th>';
echo ' <th scope="col">Voraussichtliches Ende</th>';
echo ' <th scope="col">Stillstand</th>';
echo ' <th scope="col">Einrichtzeit</th>';
echo ' <th scope="col">Avg TPP</th>';
echo ' <th scope="col">Auftragsstart</th>';
echo ' <th scope="col">Laufzeit</th>';
echo ' </tr>';
echo ' </thead>';
echo ' <tbody>';
$result = mysqli_query($db->link, "SELECT * FROM `Workorder` WHERE isLocked = 0");
while ($row = mysqli_fetch_assoc($result))
{
$wo = $row['idWorkOrder'];
$article = $db->getArticle($wo);
$articleString = $db->getArticleString($db->getArticle($wo));
$db->getAllTimeStamps($wo);
$estimatedCompletion;
$estimatedCompletionFormatted;
if ($db->getEstimatedCompletion($wo) == 0)
{
$estimatedCompletionFormatted = "no data";
}
else
{
$estimatedCompletion = $db->getEstimatedCompletion($wo) + time();
$estimatedCompletionFormatted = date('Y-m-d - H:i:s', $estimatedCompletion);
}
$machinePerformance = $db->machinePerformance($wo);
$machinePerformance = ($machinePerformance - 100) * - 1;
$configPerformance = $db->getConfigPerformance($wo);
$configPerformance = ($configPerformance - 100) * - 1;
$avgTimePerPiece = $db->calculateAverageTimePerPieceTotal($wo);
$firstTimeStamp = $db->getFirstTimeStamp($wo);
$start = date('Y-m-d - H:i:s', $firstTimeStamp);
$mostRecentTimeStamp = $db->getMostRecentTimeStamp($wo);
$timeInProduction = $mostRecentTimeStamp - $firstTimeStamp;
$timeInProductionFormatted = floor($timeInProduction / 3600) .
gmdate(":i:s", $timeInProduction % 3600);
echo ' <tr>';
echo ' <td>'. $wo .'</td>';
echo ' <td>'.$articleString.'</td>';
echo ' <td>'.$estimatedCompletionFormatted.'</td>';
echo ' <td>'.$machinePerformance.'%</td>';
echo ' <td>'.$configPerformance.'%</td>';
echo ' <td>'.(int)$avgTimePerPiece.'</td>';
echo ' <td>'.$start.'</td>';
echo ' <td>'.$timeInProductionFormatted.'</td>';
echo ' </tr>';
}
echo ' </tbody>';
echo ' </table>';
?>
答案 0 :(得分:0)
您可以使用setInterval()
更新秒数,然后创建更多功能来触发分钟和小时的更改。