C# - 今天通过的总分钟直到现在 [英] C# - total minutes passed today up until now
问题描述
你好,
给我的问题是要求我返回今天通过的总分钟数(即现在的时间)。
我知道正确的代码格式是 myDateTime.TimeOfDay.TotalMinutes 。
这将给我们分钟数已经过了从午夜开始的myDateTime代表的那一天。
当我尝试下面的代码时,我得到一个错误(波浪形的红线)说不能暗示将类型'double'转换为'int'。存在显式转换(您是否错过了演员?)。这是什么意思,有人可以更正我的代码吗?正确的答案不应该长,因为它是一个简单的培训课程。我知道我离正确答案不太远。
谢谢。
我尝试过:
Hi there,
A question given to me is asking me to return the total minutes passed today until now (i.e. the time right now).
I know the right code format is myDateTime.TimeOfDay.TotalMinutes.
which will give us the number of minutes that have passed in the day represented by myDateTime starting from midnight.
When I tried the code below, I got an error (squiggly red line) saying cannot implicity convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?). What does this mean and can someone correct my code please? The right answer shouldn't be long as it is a simple training course. I know I'm not too far off from the right answer.
Thanks.
What I have tried:
{
/****************************************************************
Return how many minutes have passed today up to now.
*****************************************************************/
public static int GetTotalMinutes()
{
return DateTime.Now.TimeOfDay.TotalMinutes;
}
}
}
推荐答案
public static int GetTotalMinutes()
{
return (int)DateTime.Now.TimeOfDay.TotalMinutes;
}
这篇关于C# - 今天通过的总分钟直到现在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!