[英]convert float number into time format?
Is there a way to convert float number to time format using html? 有没有办法使用html将浮点数转换为时间格式? For example if you have number 8.5
, it would output 08:30
? 例如,如果您有8.5
,它将输出08:30
?
I have something like this: 我有这样的事情:
<p><strong>${object.some_time}<strong></p> <!-- So this outputs that number -->
And I get this output: 我得到以下输出:
8.5 8.5
But I would like to get this output: 但我想得到以下输出:
08:30 08:30
Update I tried this: 更新我尝试了这个:
<p><strong>${object.some_time // 1}:${object.some_time % 1 * 60}<strong></p>
Then it outputs this: 然后输出:
8.0:30.0 If I put int()
around either calculation, I don't get any output. 8.0:30.0如果我将int()
放在任一计算周围,则不会获得任何输出。 So I think I can't for some reason convert types.. 因此,我认为出于某些原因我无法转换类型。
Maybe try this way : 也许这样尝试:
This should sove your probem 这应该解决您的问题
option 1: add a functional field which convert the float value to time string. 选项1:添加一个功能字段,将浮点值转换为时间字符串。 Then use the functional field in your html. 然后在您的html中使用function字段。
option 2: create a method to convert the float to time string. 选项2:创建一个将float转换为时间字符串的方法。 Then call the function from your html code. 然后从您的html代码中调用该函数。 option 3: i havent tried this. 选项3:我还没有尝试过。
${int(object.some_time // 1)}:${int(object.some_time % 1 * 60)} $ {int(object.some_time // 1)}:$ {int(object.some_time%1 * 60)}
You can use following method to convert the float to time string. 您可以使用以下方法将浮点数转换为时间字符串。
function get_time_string(sometime) {
currentHours =some_time // 1;
currentMinutes = int(object.some_time % 1 * 60);
if(currentHours <= 9){
currentHours = "0" + currentHours;
}
if(currentMinutes <= 9) {
currentMinutes = "0" + currentMinutes;
}
return currentHours+":"+currentMinutes;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.