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

我想取出系统的时间按照自己的格式输出写到这不会了
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class simpledateformate {

 private SimpleDateFormat sdf=null;
private SimpleDateFormat buf;
 public String getDate()
 {
 StringBuffer buf = new StringBuffer();
 Calendar calendar = new GregorianCalendar();
 buf.append(calendar.get(Calendar.YEAR));
 buf.append(calendar.get(Calendar.MONTH));
 buf.append(calendar.get(Calendar.DAY_OF_MONTH));
 buf.append(calendar.get(Calendar.HOUR_OF_DAY));
 buf.append(calendar.get(Calendar.MINUTE));
 this.sdf= new SimpleDateFormat("yyyy年MM月dd日hh小时mm分");
     buf =this.sdf.format(new Date());

return  buf;
 }
public static void main(String[] args) {
System.out.println(new simpledateformate().getDate());
}
}
我这个是有错的往下不会写了,帮我写好以下,最好有讲解为什么这么写 多谢

------解决方案--------------------
干嘛这么写啊 麻烦
private String getTimeStamp_yMd2(){
      SimpleDateFormat yMd2 = new SimpleDateFormat("yyyy年MM月dd日 HH小时mm分");
      return yMd2.format(new Date());
 }
试试这个