if (ObjectUtil.isNotNull(response.getCreatedTs())) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(response.getCreatedTs());
calendar.add(Calendar.DATE, 5);
Date date = new Date();
if (calendar.getTime().compareTo(date) > 0) {
Integer day = 0;
Integer hour = 0;
Integer minute = 0;
Integer second = 0;
//毫秒差值
Long differ = calendar.getTimeInMillis() - date.getTime();
day = Math.toIntExact(differ / (24 * 60 * 60 * 1000));
differ -= (24 * 60 * 60 * 1000 * day);
hour = Math.toIntExact(differ / (60 * 60 * 1000));
differ -= (60 * 60 * 1000*hour);
minute = Math.toIntExact(differ / (60 * 1000));
differ -= (60 * 1000*minute);
second = Math.toIntExact(differ / (1000));
//response.setResidueTime(String.format("请尽快支付,订单还剩 %s天 %s时 %s分 自动关闭", day, hour, minute));
response.setResidueTime(String.format("请尽快支付,订单还剩 %s天 %s时 %s分 %s秒 自动关闭", day, hour, minute, second));
} else {
response.setResidueTime("由于您超过5天未支付,交易已自动取消,请重新下单");
}
}
版权归属:
王小木人个人技术文章记录
许可协议:
本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
评论区