计算两个时间相隔的小时数
代码语言:javascript复制import java.time.Duration;
import java.time.LocalDateTime;
public class Hello {
public static void main(String[] args) {
/**
* now=2023-12-24T18:13:21.918
* hours=-8
*/
LocalDateTime now = LocalDateTime.now();
System.out.println("now=" now);
LocalDateTime dateTime = LocalDateTime.of(2023,12,24,10,0,0);
long hours = Duration.between(now,dateTime).toHours();
System.out.println("hours=" hours);
}
}