Convert Decimal to Hours Minutes and Seconds in C#

2020-06-12 04:30发布

I have an minutes field in a database like 138.34 that I need to convert back to HH:MM:SS What is the easiest way to do this?

标签: c#
2条回答
我只想做你的唯一
2楼-- · 2020-06-12 04:54

You can use the TimeSpan.FromMinutes(minutesInDouble), pass the above value in double format. For more information - check MSDN link here

查看更多
老娘就宠你
3楼-- · 2020-06-12 05:07

Use the TimeSpan structure:

var timeSpan = TimeSpan.FromMinutes(138.34);
int hh = timeSpan.Hours;
int mm = timeSpan.Minutes;
int ss = timeSpan.Seconds;

Result:

Console.WriteLine("Hours:{0} Minutes:{1} Seconds:{2}", hh, mm, ss);
// Hours:2 Minutes:18 Seconds:20
查看更多
登录 后发表回答