关于java获取当前时间前一周、前一月、前一年的时间
生活随笔
收集整理的這篇文章主要介紹了
关于java获取当前时间前一周、前一月、前一年的时间
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar c = Calendar.getInstance();//過(guò)去七天
c.setTime(new Date());
c.add(Calendar.DATE, - 7);
Date d = c.getTime();
String day = format.format(d);
System.out.println("過(guò)去七天:"+day);//過(guò)去一月
c.setTime(new Date());
c.add(Calendar.MONTH, -1);
Date m = c.getTime();
String mon = format.format(m);
System.out.println("過(guò)去一個(gè)月:"+mon);//過(guò)去三個(gè)月
c.setTime(new Date());
c.add(Calendar.MONTH, -3);
Date m3 = c.getTime();
String mon3 = format.format(m3);
System.out.println("過(guò)去三個(gè)月:"+mon3);//過(guò)去一年
c.setTime(new Date());
c.add(Calendar.YEAR, -1);
Date y = c.getTime();
String year = format.format(y);
System.out.println("過(guò)去一年:"+year);
出處:https://www.cnblogs.com/bunuo/p/6140750.html
轉(zhuǎn)載于:https://www.cnblogs.com/parable/p/11212089.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的关于java获取当前时间前一周、前一月、前一年的时间的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: pycharm设置字体和背景色
- 下一篇: [Jobdu] 题目1500:出操队形