2008-03-19
字符串"yyyy-MM-dd"日期,自动加X天后,还返回"yyyy-MM-dd"日期格式
public static String addDate(String day,int x)
{
Date date = null;
try
{
date = sdf.parse(day);
}
catch (ParseException ex)
{
ex.printStackTrace();
}
if (date==null) return "";
Calendar cal=Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DAY_OF_MONTH,x);
date=cal.getTime();
// System.out.println("after(or before) days is "+format.format(date));
cal=null;
return sdf.format(date);
}
{
Date date = null;
try
{
date = sdf.parse(day);
}
catch (ParseException ex)
{
ex.printStackTrace();
}
if (date==null) return "";
Calendar cal=Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DAY_OF_MONTH,x);
date=cal.getTime();
// System.out.println("after(or before) days is "+format.format(date));
cal=null;
return sdf.format(date);
}
发表评论
- 浏览: 22920 次
- 性别:

- 来自: 青岛

- 详细资料
搜索本博客
我的相册
111 046
共 4 张
共 4 张
最新评论
-
JAVA数据类型转换
谢谢楼主,说的很详细,好好学习下!
-- by sky21 -
JAVA数据类型转换
虽然是基础的东西, 但能总结出来还不错, 虽然有某些欠缺
-- by zhanjia -
15位和18位身份证的正则表 ...
不错,我收藏了
-- by jasongreen -
15位和18位身份证的正则表 ...
不错,我收藏了
-- by jasongreen -
DOS中 Orcle9i服务的启动 ...
呵呵
-- by jiake0504






评论排行榜