举个例子我可以说float total_Time = 228.10803
我想要的是将total_Time
转换为时间格式,这样看起来像00:03:48
我该如何做?
我想这样写:
{
float total_Time = 0;
float h = 0;
float m = 0;
float s = 0;
br.BaseStream.Position = i + 4;
total_Time = br.ReadSingle(); //reads 228.10803
total_Time = Convert.ToSingle(Math.Round(total_Time, 0));
if (total_Time < 3600)
{
h = 0;
}
else
{
h = total_Time / 3600;
h = Convert.ToSingle(Math.Round(h, 0));
total_Time = total_Time - (h * 3600);
}
m = total_Time / 60;
m = Convert.ToSingle(Math.Round(m, 0));
total_Time = total_Time - (m * 60);
s = total_Time;
s = Convert.ToSingle(Math.Round(s, 0));
SaveCS_PlayTime.Text = String.Format("Play Time: {0}:{1}:{2}", h, m, s);
}
但出于某种原因,它显示为00:4:-12
。也许我犯了一个错误。真的需要一些帮助。我知道有些帖子与我的帖子几乎相同,但没有我想要的答案。
答案 0 :(得分:7)
听起来应该将其转换为TimeSpan
,然后格式化:
using System;
class Test
{
static void Main()
{
float totalSeconds = 228.10803f;
TimeSpan time = TimeSpan.FromSeconds(totalSeconds);
Console.WriteLine(time.ToString("hh':'mm':'ss")); // 00:03:48
}
}
答案 1 :(得分:0)
要回答this,请按照以下方式使用&#34; plain&#34;数学得到时间字符串:
Process: jss.smartapp, PID: 1052
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference