我们将根据天,小时,毫秒和分钟在这里获得秒数,例如,十天内的秒数,十小时的秒数等。
持续时间(天,小时,毫秒和分钟):
Duration duration = Duration.ofDays(10); Duration duration1 = Duration.ofHours(10); Duration duration2 = Duration.ofMillis(10); Duration duration3 = Duration.ofMinutes(10);
现在,获取秒:
System.out.println("Seconds in 10 days = "+duration.getSeconds()); System.out.println("Seconds in 10 hours = "+duration1.getSeconds()); System.out.println("Seconds in 10 milliseconds = "+duration2.getSeconds()); System.out.println("Seconds in 10 minutes = "+duration3.getSeconds());
import java.time.Duration; public class Demo { public static void main(String[] args) { Duration duration = Duration.ofDays(10); Duration duration1 = Duration.ofHours(10); Duration duration2 = Duration.ofMillis(10); Duration duration3 = Duration.ofMinutes(10); System.out.println("Seconds in 10 days = "+duration.getSeconds()); System.out.println("Seconds in 10 hours = "+duration1.getSeconds()); System.out.println("Seconds in 10 milliseconds = "+duration2.getSeconds()); System.out.println("Seconds in 10 minutes = "+duration3.getSeconds()); } }
输出结果
Seconds in 10 days = 864000 Seconds in 10 hours = 36000 Seconds in 10 milliseconds = 0 Seconds in 10 minutes = 600