要什么格式的?给你个这样的“yy-mm-dd hh-mm-ss”
//根据时间字符串把天数加1
public String addOneDay(String time)
{
String add = null;
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date timeNow = df.parse(time);
Calendar begin=Calendar.getInstance();
begin.setTime(timeNow);
begin.add(Calendar.DAY_OF_MONTH,1);
add = df.format(begin.getTime());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return add;
}
这是加1的你把1改成-1就行了
获取当前时间的函数:
//获取当前时间
public String getTime() {
TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
TimeZone.setDefault(tz);
Calendar rightNow = Calendar.getInstance();
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//格式大小写有区别
String sysDatetime = fmt.format(rightNow.getTime());
return sysDatetime;
}
取消
评论
|