Java很好用的时间工具类

public classDateUtils {

private staticStrings;

private staticTimetime;

private staticDatedate;

private staticSimpleDateFormatsdf;

public staticStringgetDate() {

if(date==null) {

date=newDate();

}

if(sdf==null) {

sdf=newSimpleDateFormat("yyyy-M-d",Locale.CHINA);

}

String format =sdf.format(date);

inti = Integer.parseInt(format.split("-")[0]);

inti1 = Integer.parseInt(format.split("-")[1]);

inti2 = Integer.parseInt(format.split("-")[2]);

returni +"-"+ i1 +"-"+ i2;

}

public staticStringgetTime() {

if(time==null) {

time=newTime();

}

time.setToNow();

inthour =time.hour;

String minute =getMinute(time);

intsecond =time.second;

if(second <=9) {

if(second <=9) {

s="0"+ second;

}

returnhour +":"+ minute +":"+s;

}

returnhour +":"+ minute +":"+ second;

}

private staticStringgetMinute(Time time) {

intminute = time.minute;

if(minute <=9) {

return"0"+ minute;

}

return""+ minute;

}

public static intgetWeek() {

if(time==null) {

time=newTime();

}

time.setToNow();

intweekDay =time.weekDay;

returnweekDay;

}

}

你可能感兴趣的:(Java很好用的时间工具类)