美文网首页
Java很好用的时间工具类

Java很好用的时间工具类

作者: Kerry202 | 来源:发表于2017-10-19 11:53 被阅读22次

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很好用的时间工具类

      本文链接:https://www.haomeiwen.com/subject/cbduuxtx.html