天天看点

java new date格式_new Date()当前日期格式

//取系统日期

public String getDateWithString() {

Calendar now = Calendar.getInstance();

int month = now.get(Calendar.MONTH) + 1;

int day = now.get(Calendar.DAY_OF_MONTH);

int year = now.get(Calendar.YEAR);

String result = year + " 年 " + month + " 月 " + day + " 日 ";

return result;

}

//取系统日期

public String getDateWithYMD() {

Calendar now = Calendar.getInstance();

int month = now.get(Calendar.MONTH) + 1;

int day = now.get(Calendar.DAY_OF_MONTH);

int year = now.get(Calendar.YEAR);

String date = year + "-" + month + "-" + day;

return date;

}

//取系统日期

public String getDateWithNum() {

Calendar now = Calendar.getInstance();

int year = now.get(Calendar.YEAR);

int month = now.get(Calendar.MONTH) + 1;

int day = now.get(Calendar.DAY_OF_MONTH);

String smonth = "" + month;

String sday = "" + day;

if (month < 10) {

smonth = "0" + month;

}

if (day < 10) {

sday = "0" + day;

}

String date = year + smonth + sday;

return date;

}

//取系统日期

public Date getDate() {

Calendar now = Calendar.getInstance();

int month = now.get(Calendar.MONTH) + 1;

int day = now.get(Calendar.DAY_OF_MONTH);

int year = now.get(Calendar.YEAR);

String date = year + "-" + month + "-" + day;

Date result = Date.valueOf(date);

return result;

}

posted on 2008-08-27 23:51 林的 阅读(7077) 评论(0)  编辑  收藏 所属分类: java