以下代码中的long数据类型出了什么问题,该代码返回-666167296且time = 42和TimeStyle.Days?
private long ConvertToMilliSeconds(int time, TimeStyle style)
{
long t = 0;
switch (style)
{
case TimeStyle.Millisecons:
t = time;
break;
case TimeStyle.Seconds:
t = time * 1000;
break;
case TimeStyle.Minutes:
t = time * 1000 * 60;
break;
case TimeStyle.Hours:
t = time * 1000 * 60 * 60;
break;
case TimeStyle.Days:
t = time * 86400000;
break;
default:
break;
}
return t;
}
最佳答案
time
是int
,将其设置为long
或强制转换为long
或* 86400000L