计算两个时间相隔的小时数

计算两个时间相隔的小时数

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);

    }
}

 

posted on 2023-12-24 18:51  oktokeep  阅读(208)  评论(0编辑  收藏  举报