public class DateZaXiang { public static void main(String[] args){ //先回顾一下怎么获取时间 Calendar ca=Calendar.getInstance();//获取日历 System.out.println(ca.get(Calendar.YEAR));//获取当前年份 System.out.println(ca.get(Calendar.MONTH)+1);//获取当前月份 System.out.println(ca.get(Calendar.DAY_OF_MONTH));//获取当月中的当前天 System.out.println(ca.get(Calendar.DAY_OF_WEEK_IN_MONTH));//获取当周中的当前天 //获取前一天的日期,将前一天日期添加到日历中即可 ca.add(Calendar.DAY_OF_MONTH, -1); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); System.out.println(sdf.format(ca.getTime())); //数字格式化器,左边补0 int s=123; DecimalFormat df=new DecimalFormat("0000"); System.out.println(df.format(s)); } }
public class DateZaXiang {public static void main(String[] args){//先回顾一下怎么获取时间Calendar ca=Calendar.getInstance();//获取日历System.out.println(ca.get(Calendar.YEAR));//获取当前年份System.out.println(ca.get(Calendar.MONTH)+1);//获取当前月份System.out.println(ca.get(Calendar.DAY_OF_MONTH));//获取当月中的当前天System.out.println(ca.get(Calendar.DAY_OF_WEEK_IN_MONTH));//获取当周中的当前天//获取前一天的日期,将前一天日期添加到日历中即可ca.add(Calendar.DAY_OF_MONTH, -1);SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");System.out.println(sdf.format(ca.getTime()));//数字格式化器,左边补0int s=123;DecimalFormat df=new DecimalFormat("0000");System.out.println(df.format(s));}}