试题:输入一个日期,获取它的下一天
在Java中,时间是以毫秒来储存的,只需要将当前日期的毫秒数,加上一天的毫秒数,就可以得到下一天的日期
import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Nextday {
public static Date nextday(Date d){
long daytime=1*24*60*60*1000;
Date nd= new Date(d.getTime()+daytime);
return nd;
}
public static void nextdayformat(String s){
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
try{
Date dt=df.parse(s);
System.out.println(df.format(nextday(dt)));
}
catch (ParseException e) {
System.out.println("输入的日期格式有误!");
}
}
public static void main(String arg[]){
nextdayformat("1989-2-28");
}
}