提问阿 高手请进!

DalianBst 2003-04-03 09:33:27
想取得昨天的日期和明天的日期 怎么做阿?

就像网页上的“前一天”--“后一天”一样的
...全文
34 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
acefr 2003-04-03
  • 打赏
  • 举报
回复
没关系的,没有分的问题我也会答,呵呵。在这里都是来学习的呀。
DalianBst 2003-04-03
  • 打赏
  • 举报
回复
谢谢! 不过分有点少:)
acefr 2003-04-03
  • 打赏
  • 举报
回复
java.util.Date里可以用这个例子,(当前日期加7天的,你改一下就可以用了)
Date today=new Date();
int fYear=0,fMonth=0,fDate=0;
if((today.getDate()+7)>getday(today.getYear()+1900,today.getMonth()))
{
fMonth=today.getMonth()+2;
fDate=today.getDate()+7-getday(today.getYear()+1900,today.getMonth());
if(fMonth>12)
{
fMonth=1;
fYear=today.getYear()+1901;
}
else
{
fYear=today.getYear()+1900;
}
}
else
{
fYear=today.getYear()+1900;
fMonth=today.getMonth()+1;
fDate=today.getDate()+7;
}
acefr 2003-04-03
  • 打赏
  • 举报
回复
add
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.
DalianBst 2003-04-03
  • 打赏
  • 举报
回复
java.util.Calendar


acefr 2003-04-03
  • 打赏
  • 举报
回复
你用的是?
java.util.Date?
还是
java.util.Calendar?
DalianBst 2003-04-03
  • 打赏
  • 举报
回复
可是cal.DAYE 可以减吗?
到了1号 如果再减 那到底是 0呢 还是 上个月的31? 谢谢
acefr 2003-04-03
  • 打赏
  • 举报
回复
今天的日期-1不就可以了?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧