Convert clock time to minutes
How to convert the time 11:21:21 into t开发者_如何学JAVAotal minutes?
Get the time as a TimeSpan value using the TimeOfDay method, then use the TotalMinutes method to get the time in minutes:
DateTime t = new DateTime(0, 0, 0, 11, 21, 21);
double minutes = t.TimeOfDay.TotalMinutes;
The minutes variable now contains 681.35
. If you want the value as whole minutes use Math.Round or Math.Floor, depending on how you want it rounded:
int minutes = (int)Math.Floor(t.TimeOfDay.TotalMinutes);
How about something like
totalMins = (60 * hrs) + mins + (secs / 60)
I did it like this. Thanks for astander.
I have video time sometime like this "01:22:03" sometime like this "55:43"
And I convert this time to minudes like this
public string converttomins(String val2)
{
int hrs, mins, secs;
int totalMins;
if (val2.Length > 6)
{
hrs = Convert.ToInt32(val2.Substring(0, 2));
mins = Convert.ToInt32(val2.Substring(3, 2));
secs = Convert.ToInt32(val2.Substring(6, 2));
totalMins = (60 * hrs) + mins + (secs / 60);
}
else
{
//hrs = Convert.ToInt32(val2.Substring(0, 2));
mins = Convert.ToInt32(val2.Substring(0, 2));
secs = Convert.ToInt32(val2.Substring(3, 2));
totalMins = mins + (secs / 60);
}
//Response.Write("<script>alert('" + Convert.ToString(totalMins) + "')</script>");
return Convert.ToString(totalMins) + " dakika";
}
and I send my time like this
<%# converttomins(Convert.ToString(Eval("sure"))) %>
It's worked perfectly for me.
精彩评论