Java 日期转毫秒和毫秒转日期

// 日期转毫秒 
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
long millionSeconds = sdf.parse("20120809030000").getTime();//毫秒
System.out.println(millionSeconds);

// 毫秒转日期
Calendar c = Calendar.getInstance();
c.setTimeInMillis(millionSeconds); 
Date date = c.getTime();

System.out.println(sdf.format(date));




你可能感兴趣的:(java)