/**
* 取得服务器当前的各种具体时间
* 回车:日期时间
*/
import java.util.*;
public class GetNowDate {
Calendar calendar = null;
public GetNowDate() {
calendar = Calendar.getInstance();
calendar.setTime(new Date());
}
public int getYear() {
return calendar.get(Calendar.YEAR);
}
public int getMonth() {
return 1 + calendar.get(Calendar.MONTH);
}
public int getDay() {
return calendar.get(Calendar.DAY_OF_MONTH);
}
public int getHour() {
return calendar.get(Calendar.HOUR_OF_DAY);
}
public int getMinute() {
return calendar.get(Calendar.MINUTE);
}
public int getSecond() {
return calendar.get(Calendar.SECOND);
}
public String getDate() {
return getMonth() + "/" + getDay() + "/" + getYear();
}
public String getTime() {
return getHour() + ":" + getMinute() + ":" + getSecond();
}
public String getDate2() {
String yyyy = "0000", mm = "00", dd = "00";
yyyy = yyyy + getYear();
mm = mm + getMonth();
dd = dd + getDay();
yyyy = yyyy.substring(yyyy.length() - 4);
mm = mm.substring(mm.length() - 2);
dd = dd.substring(dd.length() - 2);
return yyyy + "/" + mm + "/" + dd;
}
public String getTime2() {
String hh = "00", mm = "00", ss = "00";
hh = hh + getHour();
mm = mm + getMinute();
ss = ss + getSecond();
hh = hh.substring(hh.length() - 2, hh.length());
mm = mm.substring(mm.length() - 2, mm.length());
ss = ss.substring(ss.length() - 2, ss.length());
return hh + ":" + mm + ":" + ss;
}
}
Java-取得服务器当前的各种具体时间
最新推荐文章于 2024-08-02 02:20:51 发布