date().toString 变date

 public static void main(String[] args) {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String i=new Date().toString();
        System.out.println(i);
        Date d=new Date(i);
        System.out.println(format.format(d));


        String s = new Date().toString();
        System.out.println(s);
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd HH:mm:ss zzz yyyy", Locale.US);
            Date da = sdf.parse(s);
            System.out.println(format.format(da));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

猜你喜欢

转载自liuwang126.iteye.com/blog/1484353