java服务器时间_Java-取得服务器当前的各种具体时间

/**

* 取得服务器当前的各种具体时间

* 回车:日期时间

*/

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;

}

}


版权声明:本文为weixin_35890184原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。