首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

DateFormat类不懂,该怎么处理

2012-01-26 
DateFormat类不懂StringtodaynullDatedatenewDate()//输出date为什么是null呢,DateFormatformatnewSi

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); //还有这个

热点排行