public class TestDateFormat {
public static void main(String[] args ) throws ParseException { // 检查时异常,要求必须做处理,处理方式有两种 throws ,try-catch-finally
Scanner input = new Scanner(System. in );
//(1)DateFormat 对象
DateFormat df = new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss.SSS " ); // 多态,父类 new 子类对象
df = new SimpleDateFormat( "yyyy-MM-dd" );
Date d = new Date(); // 得到当前的系统时间
// 格式化日期,实际上就是将 Date-->String 类型
String strDate = df.format(d);
System. out .println( strDate );
// 如何将 String 类型转换为 Date 类型
System. out .println( " 请输入一个日期 :yyyy-MM-dd" );
String str = input .next();
Date dStr = df.parse( str );
System. out .println( dStr );
}
}
date类学习【五】
猜你喜欢
转载自blog.csdn.net/wyqwilliam/article/details/92801389
今日推荐
周排行