C中时差代码的Java等价语法#
如何在java中编写c#代码C中时差代码的Java等价语法#,java,c#,datetime,Java,C#,Datetime,如何在java中编写c#代码 var startTime = DateTime.Now; //some code Duration = DateTime.Now.Subtract(startTime).TotalMilliseconds; 持续时间变量中的值是float。基本相同 Date startTime = new Date(); //some code long duration = new Date().getTime() - startTime.getTime();
var startTime = DateTime.Now;
//some code
Duration = DateTime.Now.Subtract(startTime).TotalMilliseconds;
持续时间变量中的值是float。基本相同
Date startTime = new Date();
//some code
long duration = new Date().getTime() - startTime.getTime();
你可以在这里找到你想要的:谢谢@Maylo,上面链接中给出的解决方案对我很有效。不要使用过时的
日期
类。在这种情况下,System.currentTimeMillis()
就足够了。如果需要日期时间类,请使用Instant
from。