Date和String之间的转化

// Date类型转换为String
Date now = new Date();
SimpleDateFormat sdf
= new SimpleDateFormat( " yyyy-MM-dd " );
String nowTime
= sdf.format(now);
// String类型转换为Date
String s = " 2008-01-15 " ;
String[] a
= s.split( " [-] " );
Date d
= new Date(Integer.parseInt(a[ 0 ]),Integer.parseInt(a[ 1 ]),Integer.parseInt(a[ 2 ]));

你可能感兴趣的:(String)