DDDYYYUUU 2021-09-27 12:56 采纳率: 50%
浏览 35

Java提问 刚开始学Java 该怎么做呀

计算从2000月30日到现在经历了多少天?(提示:使用Calendar类,计算2000年5月30日到现在过去了多少毫秒,然后换算成天数)

  • 写回答

2条回答 默认 最新

  • codeallen2013 2021-09-27 13:26
    关注

    1.毫秒算法
    public static long getDays(Date small, Date big) {
    if (small == null) {
    return 0;
    }
    if (big == null) {
    return 0;
    }
    long day = (big.getTime() - small.getTime()) / (24 * 60 * 60 * 1000);
    return day;
    }
    2.可以使用java8的Instant
    public static long toDays(Date startDate, Date endDate) {
    Instant startDateInstant = startDate.toInstant();
    Instant endDateInstant = endDate.toInstant();
    return Duration.between(startDateInstant, endDateInstant).toDays();
    }

    评论

报告相同问题?

问题事件

  • 创建了问题 9月27日

悬赏问题

  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用