时间码有百分之几吗?
一直在从十进制秒创建时间代码格式,但现在需要将百分之一转换为格式。
所以在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
secs % 1
将从1.5
生成0.5
或从123.456
生成0.456
,当您将其乘以100
,即可得到要显示的百分之数。然后对结果进行四舍五入。更新:有人指出你可能想要女士。只需将
1000
替换为100
即可。secs % 1
will make0.5
from1.5
or0.456
from123.456
and when you multiply that by100
, 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 the100
.