Date d=new Date();//当天
Date date=new Date(d.getYear(),d.getMonth(),d.getDay()-3);//3天前
Date date=new Date(d.getYear()-1,d.getMonth(),d.getDay());//1年前
要作适当处理,比如d.getDay()-3<=0时,自己看着处理吧
Date date=new Date(d.getYear(),d.getMonth(),d.getDay()-3);//3天前
Date date=new Date(d.getYear()-1,d.getMonth(),d.getDay());//1年前
要作适当处理,比如d.getDay()-3<=0时,自己看着处理吧
解决方案 »
- vassdk_soap.jar
- File类对象 renameTo(File des) 为什么返回false?
- 菜鸟求助~
- new Runnable() 问题?
- 实现接口,为什么一定要实现接口中的所有方法
- 如何设置default按钮
- java如何检查文件是否可写(被占用)
- 说我使用不合法的API?关于canvas
- Applet中如何达到save,load的功能?(除了数字签名)
- Use of variable as components name?
- 如何使用java,调用Visual Basic的ActiveX Dll???(100)
- 如何在写入文件时实现回车功能,即换行!多谢,一定给分。在线等待!
int smonth = getIntFromCombox(startMonthCb);
int sdate = getIntFromCombox(startDateCb);
int shour = getIntFromCombox(startHourCb);
int eyear = getIntFromCombox(endYearCb);
int emonth = getIntFromCombox(endMonthCb);
int edate = getIntFromCombox(endDateCb);
int ehour = getIntFromCombox(endHourCb); ts_after3 = new Timestamp(syear-1900 + 3,1-1,1,0,0,0,0);
ts_before3 = new Timestamp(eyear-1900 - 3,12-1,31,23,59,59,999999999);
Timestamp(eyear-1900 - 3,12-1,31,23,59,59,999999999);
?多谢了!还有:GregorianCalendar now=new GregorianCalendar();
now.add(1,n);n是30的时候就不好使了??
看jdk的Calendar帮助!public abstract void add(int field,int amount)
Date Arithmetic function. Adds the specified (signed) amount of time to the given time field, based on the calendar's rules. For example, to subtract 5 days from the current time of the calendar, you can achieve it by calling:
add(Calendar.DATE, -5).
Parameters:
field - the time field.
amount - the amount of date or time to be added to the field.而且这里的add还有选择的方式,详细看看jdk吧,里边有答案。
关键他的好处在于:add(int field,int amount)中的field参数,有不少常量,很方便,DAY_OF_YEAR,DAY_OF_MONTH,WEEK_OF_MONTH,WEEK_OF_YEAR
总之,很多吧。
我曾用jdk1。3写过一个类似window系统的日历组件就是用的Calendar,好使!
int amount)
Date Arithmetic function. Adds the specified (signed) amount of time to the given time field, based on the calendar's rules. For example, to subtract 5 days from the current time of the calendar, you can achieve it by calling:
add(Calendar.DATE, -5).Parameters:
field - the time field.
amount - the amount of date or time to be added to the field.
我用的是GregorianCalendar。
再次感谢!!!
我已经解决问题了。