Adding/Subtracting 5 seconds from Java Date - Showing deprected warning

后端 未结 8 879
旧巷少年郎
旧巷少年郎 2021-01-23 01:43

I want to add 5 seconds to current time

    Date date = new Date();

    date.setSeconds(date.getSeconds()+ 5);
    System.out.println(\"old Value is: \"+date);         


        
8条回答
  •  长情又很酷
    2021-01-23 02:12

    Java 8 has completly different time-api and makes handling dates a lot easier. Here's an article

    With Java Versions 5-7 (everything below should not be used IMHO) you should use Calendar (as Petr suggested) If you are allowed to use third-party APIs, you should definitly take a look at JodaTime

提交回复
热议问题