Java - 서버의 현재 시점 파악
                                            
 1572 단어  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;
	}
}
                이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Java 언어에서 null과 ""의 차이Java 언어로 프로그래밍을 배우고 사용하는 개발자는 다음과 같은 코드를 자주 만날 수 있습니다. 저희가 꼼꼼히 생각하지 못할 때가 많아요. null과 양자의 차이는 단지 이렇게 쓰면 된다는 것을 알 뿐이지만, 그것...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.