//获取当前时间
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, 3); //现在时间的3天后
cal.set(Calendar.HOUR_OF_DAY, 8);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
//MILLISECOND也要设为0, 否则写入数据库时会发生SECOND为1的情况
cal.set(Calendar.MILLISECOND, 0);
// 转换为Date
Date date=cal.getTime();
//转换为Timestamp
Timestamp expire = new Timestamp(date.getTime());
使用Calendar获取并修改时间
最新推荐文章于 2024-08-07 07:00:00 发布