1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Java日期:今天 昨天 某一天 某一天的前一天

Java日期:今天 昨天 某一天 某一天的前一天

时间:2020-11-18 13:18:55

相关推荐

Java日期:今天 昨天 某一天 某一天的前一天

Java日期:今天,昨天,某一天,某一天的前一天

当前系统时间

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式

昨天

public static void main(String[] args){Calendar calendar = Calendar.getInstance();calendar.add(Calendar.DATE, -1); //得到前一天Date date = calendar.getTime();DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");System.out.println(df.format(date));}

任意一天的前一天

public String method1(String specifiedDay){ Calendar c = Calendar.getInstance(); Date date = null; try{ date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay); }catch (Exception e) { e.printStackTrace(); } c.setTime(date); int day = c.get(Calendar.DATE); c.set(Calendar.DATE, day-1); String dayBefore = new SimpleDateFormat("yyyy-MM-dd).format(c.getTime()); return dayBefore; }

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。