如何在 Java 中使用 TimeUnit
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47717633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use TimeUnit in java
提问by Ibraheem Alayan
I am trying to use TimeUnit in java but it just send me errors That's how I wrote it
我正在尝试在 Java 中使用 TimeUnit,但它只是向我发送错误这就是我写的
import java.util.concurrent.TimeUnit ;
Public class anything {
Public static void main( String[ ] args ) {
System.out.println(“hi”);
TimeUnit.SECONDS.sleep(6);
System.out.println(“hi”);
}
}
回答by Lalit Verma
Try this as your code have many syntax errors
as well as you are not handling Exception
during the call of TimeUnit.SECONDS.sleep(6);
, either use throws or surround this with try catch.
试试这个,因为你的代码有很多syntax errors
以及你handling Exception
在 调用期间没有的TimeUnit.SECONDS.sleep(6);
,要么使用 throws,要么用 try catch 包围它。
import java.util.concurrent.TimeUnit ;
public class Anything {
public static void main( String[] args ) throws InterruptedException {
System.out.println("hi");
TimeUnit.SECONDS.sleep(6);
System.out.println("hi");
}
}