赞
踩
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”); 格式化时间格式
new Date() 获取当前的时间
Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
calendar.add(calendar.DATE,-1);
String yesterday = sdf.format(calendar.getTime());先把当前时间放在上面,-1就是昨天的现在,1就是明天现在,2就是后天的现在
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("今天:"+sdf.format(new Date()));
//获取昨天日期
Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
calendar.add(calendar.DATE,-1);
String yesterday = sdf.format(calendar.getTime());
System.out.println("昨天:"+yesterday);
Calendar calendar2 = new GregorianCalendar();
calendar2.setTime(new Date());
calendar2.add(calendar2.DATE,1);
System.out.println("明天:"+sdf.format(calendar2.getTime()));
"明天:"+sdf.format(calendar2.getTime()));
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。