由于业务中有一项需求需要在新员工三个月快转正的时候发邮件,所以写个小例子看看效果
时间在实体类中是long型,所以想的是先转出date,用calender计算加75天之后再转成String显示
pasting
public static void main(String args[]) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
long longTime = new Date().getTime();
System.out.println("long为:" + longTime);
System.out.println("Long转换成日期:");
System.out.println("longToDate:" + new SimpleDateFormat("yyyy-MM-dd ").format(new Date(longTime)));
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date(longTime));
calendar.add(Calendar.DAY_OF_MONTH, +75);
System.out.println("75天后:" + sdf.format(calendar.getTime().getTime()));
}
测试结果如下long为:1529133715787
Long转换成日期:
longToDate:2018-06-16
75天后:2018-08-30