时间码有百分之几吗?

发布于 2025-01-06 02:28:15 字数 770 浏览 2 评论 0原文

一直在从十进制秒创建时间代码格式,但现在需要将百分之一转换为格式。

所以在 1.5 秒内我需要得到 00:00:01:050 但我需要一些帮助,因为没有到达任何地方!

任何帮助表示赞赏... D.

function secondsToTime(secs) {

    var hours = Math.floor(secs / (60 * 60));

    var divisor_for_minutes = secs % (60 * 60);
    var minutes = Math.floor(divisor_for_minutes / 60);

    var divisor_for_seconds = divisor_for_minutes % 60;
    var seconds = Math.ceil(divisor_for_seconds);

    // guesswork! 
    var divisor_for_hund = divisor_for_seconds / 100;
    var hund = divisor_for_hund;

    var obj = {
        "tc": pad(hours, 2) + ':' + pad(minutes, 2) + ':' + pad(seconds, 2)+ ':' + pad(hund, 3),
        "h": pad(hours, 2),
        "m": pad(minutes, 2),
        "s": pad(seconds, 2)
    };
    return obj;
}

Been creating a time code format from decimal seconds but now need to get hundredths into the format.

so for 1.5 secs i need to get 00:00:01:050 but i need some help as not getting anywhere!

Any help appreciated... D.

function secondsToTime(secs) {

    var hours = Math.floor(secs / (60 * 60));

    var divisor_for_minutes = secs % (60 * 60);
    var minutes = Math.floor(divisor_for_minutes / 60);

    var divisor_for_seconds = divisor_for_minutes % 60;
    var seconds = Math.ceil(divisor_for_seconds);

    // guesswork! 
    var divisor_for_hund = divisor_for_seconds / 100;
    var hund = divisor_for_hund;

    var obj = {
        "tc": pad(hours, 2) + ':' + pad(minutes, 2) + ':' + pad(seconds, 2)+ ':' + pad(hund, 3),
        "h": pad(hours, 2),
        "m": pad(minutes, 2),
        "s": pad(seconds, 2)
    };
    return obj;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情稳全场 2025-01-13 02:28:15
var hundredths = Math.round((secs % 1) * 100);

secs % 1 将从 1.5 生成 0.5 或从 123.456 生成 0.456,当您将其乘以 100,即可得到要显示的百分之数。然后对结果进行四舍五入。

更新:有人指出你可能想要女士。只需将 1000 替换为 100 即可。

var hundredths = Math.round((secs % 1) * 100);

secs % 1 will make 0.5 from 1.5 or 0.456 from 123.456 and when you multiply that by 100, you get the number of hundredths you want to display. Then just round the result.

Update: It was pointed out you probably want ms. Just put 1000 in place of the 100.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文