日期:2014-05-20  浏览次数:20587 次

DateFormat类不懂
String   today=null;
Date   date=new   Date();     //输出date为什么是null呢,
DateFormat   format=new   SimpleDateFormat( "yyyy-MM-dd ");     //看API没看懂,DateFormat是个什么类,起的什么作用,为什么要用它,   还有为什么要用new   SimpleDateFormat( "yyyy-MM-dd ");     初始化呢
today   =   format.format(date);     //还有这个

------解决方案--------------------
String today=null;
Date date=new Date(); //输出date为什么是null呢,
----------
是当前时间,不会是null的


DateFormat format=new SimpleDateFormat( "yyyy-MM-dd "); //看API没看懂,DateFormat是个什么类,起的什么作用,为什么要用它,
------------------
日期格式化的
你可以年月日,也可以日月年,还可以用其他的方式
比如:DateFormat format=new SimpleDateFormat( "yyyy年MM月dd不日 ");


还有为什么要用new SimpleDateFormat( "yyyy-MM-dd "); 初始化呢
today = format.format(date); //还有这个