当前位置: 代码迷 >> J2SE >> 如何样输出这种格式的日期的字符串呀?“2007-04-05"
  详细解决方案

如何样输出这种格式的日期的字符串呀?“2007-04-05"

热度:113   发布时间:2016-04-24 16:33:01.0
怎么样输出这种格式的日期的字符串呀?“2007-04-05"
怎么样输出这种格式的日期的字符串呀?“2007-04-05 "

------解决方案--------------------
java.text.DateFormat f=new java.util.SimpleDateFormat( "yyyy-MM-dd ");
java.util.Date d=new java.util.Date();
System.out.println(f.format(d));


自己去看看api文档,里面都!!!!!


另外看看csdn已经解决的帖子,有N多!!!!


就知道问!!!!!!!!!!


自己动手、动脑!
------解决方案--------------------
public static final String getDateString(java.util.Date aDate) {
String ret = " ";
Calendar c = Calendar.getInstance();
c.setTime(aDate);

ret = c.get(Calendar.YEAR) + "- " ;
ret = ret + addZero((c.get(Calendar.MONTH)+1) + " ", 2) + "- " ;
ret = ret + addZero((c.get(Calendar.DAY_OF_MONTH)) + " ", 2) + " " ;
ret = ret + addZero((c.get(Calendar.HOUR_OF_DAY)) + " ", 2) + ": " ;
//ret = ret + addZero((c.get(Calendar.MINUTE)) + " ", 2) + ": ";
//ret = ret + addZero((c.get(Calendar.SECOND)) + " ", 2);
return ret;
}
  相关解决方案