在工业互联网项目中,经常需要生成时间计划,方便对工艺进程进行把控。下面的这段代码,帮助我们预估未来的时间
public static void main(String[] args) {
Date date = new Date(); // 已知的时间节点
Duration duration = Duration.ofHours(2).plusMinutes(30).plusSeconds(10); // 增加的时间差, 这里假设根据当前时间增加 2小时30分钟10秒,即两个半小时以后的时间。
Instant instant = date.toInstant(); // 将 Date 转换为 Instant
Instant newInstant = instant.plus(duration); // 加上时间差得到新的 Instant
Date newDate = Date.from(newInstant); // 将 Instant 转换为 Date
System.out.println("原始时间节点:" + date);
System.out.println("增加后的时间节点:" + newDate);
}
这个方法在工业项目中可能经常使用到,希望能给大家提供一些参考。点赞支持一下吧!