当前位置: 技术问答>java相关
如何实现前一日,后一日的移动?
来源: 互联网 发布时间:2014-12-27
本文导语: 如何实现前一日,后一日的移动? 请写的全一些, 谢谢! | String DATE_FORMAT = "yyyy-MM-dd"; java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT); Calendar c1 = Calendar.getInst...
如何实现前一日,后一日的移动?
请写的全一些,
谢谢!
请写的全一些,
谢谢!
|
String DATE_FORMAT = "yyyy-MM-dd";
java.text.SimpleDateFormat sdf =
new java.text.SimpleDateFormat(DATE_FORMAT);
Calendar c1 = Calendar.getInstance();
// roll down the month
c1.set(1999, 0 , 20); // 1999 jan 20
System.out.println("Date is : " + sdf.format(c1.getTime()));
c1.roll(Calendar.MONTH, false); // roll down, substract 1 month
System.out.println("Date roll down 1 month : " + sdf.format(c1.getTime())); // 1999 jan 20
c1.set(1999, 0 , 20); // 1999 jan 20
System.out.println("Date is : " + sdf.format(c1.getTime()));
c1.add(Calendar.MONTH, -1); // substract 1 month
System.out.println("Date minus 1 month : " + sdf.format(c1.getTime())); // 1998 dec 20
java.text.SimpleDateFormat sdf =
new java.text.SimpleDateFormat(DATE_FORMAT);
Calendar c1 = Calendar.getInstance();
// roll down the month
c1.set(1999, 0 , 20); // 1999 jan 20
System.out.println("Date is : " + sdf.format(c1.getTime()));
c1.roll(Calendar.MONTH, false); // roll down, substract 1 month
System.out.println("Date roll down 1 month : " + sdf.format(c1.getTime())); // 1999 jan 20
c1.set(1999, 0 , 20); // 1999 jan 20
System.out.println("Date is : " + sdf.format(c1.getTime()));
c1.add(Calendar.MONTH, -1); // substract 1 month
System.out.println("Date minus 1 month : " + sdf.format(c1.getTime())); // 1998 dec 20
|
算了,我不说了,楼上的都说清楚啦,呵呵