java获取上一年年份输出
程序员文章站
2022-06-07 12:11:58
...
package mytest;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class TestLastYear {
public static void main(String[] args) {
SimpleDateFormat formats = new SimpleDateFormat("yyyy");
Calendar c = Calendar.getInstance();
c.add(Calendar.YEAR,-1);
Date date = c.getTime();
System.out.println(formats.format(date));
}
}
上一篇: java函数式编程