首先,设置持续时间-
Duration duration = Duration.ofDays(25);
现在,从上述持续时间中获取具有25天的小时数-
duration.toHours()
import java.time.Duration; public class Demo { public static void main(String[] args) { Duration duration = Duration.ofDays(25); System.out.println("Hours in 25 days = "+duration.toHours()); } }
输出结果
Hours in 25 days = 600