SimpleDateFormat类用于日期转换很方便
主要是创建模板。
public class DateTest {
//模板1
private static String format1 = "yyyy-MM-dd HH:mm:ss:SSS";
//模板2
private static String format2 = "MM月dd天yy年mm分";
public static void main(String[] args) {
String strDate = "2015-10-18 12:12:12:123";
SimpleDateFormat sdf1 = new SimpleDateFormat(format1);
SimpleDateFormat sdf2 = new SimpleDateFormat(format2);
Date d = null;
try {
//使用模板1将字符串strDate表示的日期数字取出转为Date类型
d = sdf1.parse(strDate);
} catch (ParseException e) {
e.printStackTrace();
}
//将Date类型的数据以模板2的格式转换为新的字符串
System.out.println(sdf2.format(d));
}
}