java日期操作

//字符串转日期
    public static void dt7() throws ParseException {
        String str_date="2015---08---08";
        DateFormat dt=new SimpleDateFormat("yyyy--MM--dd");
        Date date=dt.parse(str_date);
        System.out.println(date);
    }

    public static void dt6() throws ParseException {
        String str_date="2015年08月08日";
        DateFormat dt=DateFormat.getDateInstance(DateFormat.LONG);
        Date date=dt.parse(str_date);
        System.out.println(date);
    }

    public static void da3() throws ParseException {
        String str_date="2015-08-08";
        DateFormat dt=DateFormat.getDateInstance();
        Date date=dt.parse(str_date);
        System.out.println(date);
    }
    
    //日期转字符串

    public static void dt3() {
        Date dt=new Date();
        DateFormat dtf=new SimpleDateFormat("yyyy-MM-dd");
        String s=dtf.format(dt);
        System.out.println(s);
    }

    public static void dt2() {
        Date dt=new Date();
        DateFormat dtf=DateFormat.getDateInstance(DateFormat.LONG);
        String s=dtf.format(dt);
        System.out.println(s);
    }

    public static void cl() {
        long time=System.currentTimeMillis();
        Date dt=new Date(20151440592355603l);
        System.out.print(dt);
        System.out.print(time);
    }
原文地址:https://www.cnblogs.com/zywf/p/4761712.html