计算列的时间总和 [英] Calculate the sum of the time for column

查看:128
本文介绍了计算列的时间总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这张桌子:

<table id="total" border="1" width="100%">
    <tbody>
        <tr>
            <td>Total duration time</td>
            <td class="total_duration_time"></td>
        </tr>
    </tbody>
</table>
<table id="data" border="1" width="100%">
    <tbody>
        <tr>
            <td>Anna</td>
            <td>318</td><td class="duration_time">00:00:50</td>
            <td>62700</td>
        </tr>
        <tr>
            <td>Bob</td>
            <td>318</td>
            <td class="duration_time">00:00:27</td>
            <td>62703</td>
        </tr>
        <tr>
            <td>Mike</td>
            <td>318</td>
            <td class="duration_time">00:00:36</td>
            <td>88455233284</td>
        </tr>
    </tbody>
</table>

我需要计算类duration_time的列的总和,并将结果打印到类total_duration_time的列中.

I need to calculate the sum of the column with class duration_time and print result in to column with class total_duration_time.

如何在JavaScript或jQuery上执行此操作?

How to do this on JavaScript or jQuery?

我尝试使用此示例中的代码 http://jsfiddle.net/unKDk/13/,但如果用数字代替00:00:00类型的值,则不会计算时间量.

I tried to use the code from this example http://jsfiddle.net/unKDk/13/, but it does not calculate the amount of time if instead of numbers substitute a value of type 00:00:00.

推荐答案

最简单的方法是花费几秒钟.我的意思是,您可以将每个持续时间转换为秒,进行总计,然后使用另一个将秒转换为hh-mm-ss格式的函数来显示您需要的位置.

The easiest way is to work with seconds. I mean, you can convert each duration to seconds, make the total and then show where you need using another function that converts the seconds to hh-mm-ss format.

您可以在此处

注意:函数toHHMMSS()是令牌形式此处

Note : the function toHHMMSS() is token form here

这篇关于计算列的时间总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆