80,349
社区成员
发帖
与我相关
我的任务
分享
public class Test3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
DateFormat formatter=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date date=null;
try {
date=formatter.parse("2017-02-15 16:03:00");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
GregorianCalendar calendar=new GregorianCalendar();
calendar.setTime(date);
System.out.println(calendar.get(Calendar.YEAR)+"-"+(calendar.get(Calendar.MONTH)+1)+"-"+calendar.get(Calendar.DAY_OF_MONTH));
System.out.println((date.getYear()+1900)+"-"+(date.getMonth()+1)+"-"+(date.getDay()+12));
}
}
或者用GregorianCalendar这个类更舒服。