package study.ExDate;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
/**
* @author admin
*
*/
public class UtilCalendar {
private static Calendar cal = Calendar.getInstance();
/**
* 현재 연월일 시분초 밀리세컨드까지 가져오는 메소드
*/
public static void getSamDate() {
disDate();
}
public static void getSetDate() {
Date date = new Date();
// 5초 추가
date.setTime(5000);
// 현재시간에 5초로 시간 설정
cal.setTime(date);
// 년
disDate();
}
/**
* 지역을 찾아서 영국과의 시간차를 빼기위한 메소드
*/
public static void getDateLocale() {
Locale lo = Locale.getDefault();
System.out.println(cal.get(Calendar.YEAR));
System.out.println(cal.get(Calendar.MONTH) + 1);
System.out.println(cal.get(Calendar.DATE) + "일");
System.out.println(cal.get(Calendar.AM_PM) + "오전오후");
if (lo.getCountry().equals("KR") && lo.getLanguage().equals("ko")) {
System.out.println(cal.get(Calendar.HOUR) - 9 + "시간");
} else {
System.out.println(cal.get(Calendar.HOUR) + "시간");
}
System.out.println(cal.get(Calendar.MINUTE) + "분");
System.out.println(cal.get(Calendar.SECOND) + "초");
System.out.println(cal.get(Calendar.MILLISECOND) + "세컨드");
System.out.println(cal.getTimeInMillis() + "");
}
public static void getUkDate() {
// 다시 객체 생성
cal = Calendar.getInstance();
TimeZone zone = TimeZone.getTimeZone("Europe/London");
cal.setTimeZone(zone);
disDate();
}
public static void useContryDate() {
String[] local = TimeZone.getAvailableIDs();
for (String s : local) {
System.out.println(s);
}
}
public static void disDate() {
// 년
System.out.println(cal.get(Calendar.YEAR));
System.out.println(cal.get(Calendar.MONTH) + 1);
System.out.println(cal.get(Calendar.DATE) + "일");
System.out.println(cal.get(Calendar.AM_PM) + "오전오후");
System.out.println(cal.get(Calendar.HOUR) + "시간");
System.out.println(cal.get(Calendar.MINUTE) + "분");
System.out.println(cal.get(Calendar.SECOND) + "초");
System.out.println(cal.get(Calendar.MILLISECOND) + "세컨드");
System.out.println(cal.getTimeInMillis() + "");
}
}