This article introduces the method of obtaining date in java, friends in need can refer to it
/*
* 获取昨天日期 方法一,这个方法好像有点慢
*/
Date dt = new Date();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
time = new SimpleDateFormat( "yyyy-MM-dd").format(cal.getTime());
/*
* 获取昨天日期 方法二
*/
Date as = new Date(new Date().getTime()-24*60*60*1000);
SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
time = matter1.format(as);
The above is the whole content of this article. If you need more information, please contact me. I hope it will be helpful to everyone's study, and I hope you can support me.