[size=large]先查看JDK文档中Date的构造方法:[/size]
Date()
Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.
Date(long date)
Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
//需要显示日期格式
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;
//当前时间
Date date = new Date() ;
//格式化时间
sf.format(date) ;
//获得昨天的时间
Date date2 = new Date(date.getTime()-1*24*60*60*1000) ;
String str =sf.format(date2) ;
System.out.println(str) ;
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss") ;
Date date = new Date() ;
sf.format(date) ;
Calendar calendar = Calendar.getInstance() ;
calendar.setTime(date) ;
// 以day为量来进行添加
// calendar.add(Calendar.DATE, 1) ;
// 以minute为量进行添加
// calendar.add(Calendar.MINUTE, 1*24*60) ;
// 以小时为量进行添加
// calendar.add(Calendar.HOUR, 1*24) ;
// 一毫秒为量进行添加
calendar.add(Calendar.MILLISECOND, 1*24*60*60*1000) ;
System.out.println(sf.format(calendar.getTime())) ;