将分钟转换为天和小时 [英] Convert Minute in to Days and Hours
本文介绍了将分钟转换为天和小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在ASP.NET中使用分钟计算天数小时分钟
ex:28983分钟= 20天21小时
解决方案
您可以使用TimeSpan类,如下代码
TimeSpan t = TimeSpan.FromSeconds(secs);
string answer = string .Format( {0:D2} h:{1:D2} m:{2:D2} s:{3:D3} ms ,
t.Hours,
t.Minutes,
t.Seconds,
t.Milliseconds);
< blockquote>嗯,这并不难,考虑到一天对应 60 * 24 = 1440
秒:
< pre lang =C#> int tot_mins = 28983 ;
int days = tot_mins / 1440 ;
int hours =(tot_mins% 1440 )/ 60;
int mins = tot_mins% 60 ;
请注意,您的示例有误:
28983总分钟 - > 20天,3小时,3分钟
尝试:
// 使用TimeSpan结构
int min = 28983 跨度>;
TimeSpan elapsedTime = new TimeSpan( 0 ,min, 0 );
int day = elapsedTime.Days;
int hour = elapsedTime.Hours;
Console.WriteLine( string .Format( {0}天{1}小时,日,小时));
// 或只是简单的数学
double 天= min / 60/24;
double hours =(min - days * 24 * 60)/ 60;
Console.WriteLine( string .Format( {0}天{1:0}小时,天,小时));
两者得到的结果相同:
20天3小时
20天3小时
how to calculate days hours minutes using minutes in ASP.NET
ex:28983 mins = 20 days 21 hrs
解决方案
You can use TimeSpan class as below code
TimeSpan t = TimeSpan.FromSeconds( secs ); string answer = string.Format("{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms", t.Hours, t.Minutes, t.Seconds, t.Milliseconds);
Well, that's not difficult, considering a day corresponds to60 * 24 = 1440
secs:
int tot_mins = 28983; int days = tot_mins / 1440; int hours = (tot_mins % 1440)/60; int mins = tot_mins % 60;
Please note, your example is wrong:28983 total minutes -> 20 days, 3 hours, 3 minutes
Try:
// Use TimeSpan structure int min = 28983; TimeSpan elapsedTime = new TimeSpan( 0, min, 0 ); int day = elapsedTime.Days; int hour = elapsedTime.Hours; Console.WriteLine(string.Format("{0} days {1} hours", day, hour)); // or just plain mathematics double days = min/60/24; double hours = (min - days*24*60)/60; Console.WriteLine(string.Format("{0} days {1:0} hours", days, hours));
Both get the same result as:
20 days 3 hours 20 days 3 hours
这篇关于将分钟转换为天和小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文