You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.7 KiB
70 lines
1.7 KiB
/********************************************************* |
|
* 프로그램명 : DateUtil.java 프로그램설명 : 날짜 관련 util로서 날짜 더하기 작 성 자 : 강 원 중 작 성 일 : 2002. 5.27 최신변경일 : 2003. 5.22 |
|
*********************************************************/ |
|
package kr.co.kihyun.util; |
|
|
|
import java.util.Calendar; |
|
|
|
public class DateUtil { |
|
String yymmdd = ""; |
|
|
|
public DateUtil() { |
|
setDate(); |
|
} |
|
|
|
private void setDate() { |
|
Calendar calendar = Calendar.getInstance(); |
|
int y = calendar.get(Calendar.YEAR); // 년 |
|
String Sy = "" + y; |
|
|
|
int m = calendar.get(Calendar.MONTH) + 1;// 월 |
|
String Sm = "" + m; |
|
if (m < 10) |
|
Sm = "0" + m; |
|
|
|
int d = calendar.get(Calendar.DATE); // 일 |
|
String Sd = "" + d; |
|
if (d < 10) |
|
Sd = "0" + d; |
|
|
|
int h = calendar.get(Calendar.HOUR_OF_DAY);// 시간 HOUR_OF_DAY 12시 이후에는 13시로 됨. |
|
String Sh = "" + h; |
|
if (h < 10) |
|
Sh = "0" + h; |
|
|
|
int mi = calendar.get(Calendar.MINUTE);// 분 |
|
String Smi = "" + mi; |
|
if (mi < 10) |
|
Smi = "0" + mi; |
|
|
|
String ymd = null; |
|
ymd = Sy + Sm + Sd + Sh + Smi; |
|
|
|
yymmdd = ymd; |
|
} |
|
|
|
public String getDate() { |
|
return yymmdd; |
|
} |
|
|
|
public String getDate(String delim) { |
|
return separator(yymmdd, delim); |
|
} |
|
|
|
public static String separator(String date, String delim) { |
|
int count = date.length(); |
|
|
|
if (count == 8) {// 20031231 |
|
date = date.substring(0, 4) + delim + date.substring(4, 6) + delim + date.substring(6, 8); |
|
return date; |
|
} else if (count == 6) { |
|
date = date.substring(0, 2) + delim + date.substring(2, 4) + delim + date.substring(4, 6); |
|
return date; |
|
} else if (count == 4) { |
|
date = date.substring(0, 2) + delim + date.substring(2, 4); |
|
return date; |
|
} else { |
|
return ""; |
|
} |
|
} |
|
}
|
|
|