반응형

//날짜에 점을 넣어줌
public static String setDotDate(String day) {
int size = day.length();
StringBuffer sb = new StringBuffer(day);

String dot = ".";

if (size == 4) {
sb.insert(2, dot);
} else if (size == 6) {
sb.insert(4, dot);
} else if (size == 8) {
sb.insert(4, dot);
sb.insert(7, dot);
}
return sb.toString();
}

//시간에 ":"을 넣어줌

public static String setDotTime(String time) {
int size = time.length();
StringBuffer sb = new StringBuffer(time);

String dot = ":";

if (size == 4) {
sb.insert(2, dot);
} else if (size == 8) {
sb.insert(4, dot);
sb.insert(7, dot);
} else if (size == 6) {
sb.insert(2, dot);
sb.insert(5, dot);
}
return sb.toString();
}

//현재 날짜가저오기

public static String getCurrentDay() {
String day = "";
Calendar calendar = Calendar.getInstance();
int today = calendar.get(Calendar.DATE);

calendar.set(Calendar.DAY_OF_MONTH, 1);

int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;

day = addZero(year) + addZero(month) + addZero(today);

return day;
}

//년월

public static String getCurrentMonth() {
String day = "";
Calendar calendar = Calendar.getInstance();
int today = calendar.get(Calendar.DATE);

calendar.set(Calendar.DAY_OF_MONTH, 1);

int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;

day = addZero(year) + addZero(month);

return day;
}

//내일

public static String getTomorrow() {
String day = "";
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DATE, 1);

int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int today = cal.get(Calendar.DAY_OF_MONTH);

day = addZero(year) + addZero(month) + addZero(today);

return day;
}

//"0"이 없을때 붙여줌.

public static String addZero(int arg) {
String val = String.valueOf(arg);

if (arg < 10)
val = "0" + val;

return val;
}

//현재시간

public static String getCurrentTime() {
String strNow = "";
// 현재 시간을 msec으로 구한다.
long now = System.currentTimeMillis();
// 현재 시간을 저장 한다.
Date date = new Date(now);
// 시간 포맷으로 만든다.
SimpleDateFormat sdfNow = new SimpleDateFormat("yyMMddHHmmss");
strNow = sdfNow.format(date);

return strNow;
}

//요일

public static String getDayOfWeek() {

String dayOfWeek = "";

Calendar cal = Calendar.getInstance();
int day_of_week = cal.get(Calendar.DAY_OF_WEEK);

switch (day_of_week) {
case 1:
dayOfWeek = "";
break;
case 2:
dayOfWeek = "";
break;
case 3:
dayOfWeek = "";
break;
case 4:
dayOfWeek = "";
break;
case 5:
dayOfWeek = "";
break;
case 6:
dayOfWeek = "";
break;
case 7:
dayOfWeek = "";
break;
}

return dayOfWeek;
}

//현재시간

public static String getCurrentTimeHHMM() {
String strNow = "";
// 현재 시간을 msec으로 구한다.
long now = System.currentTimeMillis();
// 현재 시간을 저장 한다.
Date date = new Date(now);
// 시간 포맷으로 만든다.
SimpleDateFormat sdfNow = new SimpleDateFormat("HH:mm");
strNow = sdfNow.format(date);

return strNow;
}

//8자리 날짜를 넣으면 요일구함

public static String getDayOfWeek(String date) {

int year = 0;
int month = 0;
int day = 0;

if (date.length() > 7) {
year = Integer.parseInt(date.substring(0, 4));
month = Integer.parseInt(date.substring(4, 6));
day = Integer.parseInt(date.substring(6, 8));
}
String dayOfWeek = "";

Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month - 1);
cal.set(Calendar.DATE, day);

int day_of_week = cal.get(Calendar.DAY_OF_WEEK);

switch (day_of_week) {
case 1:
dayOfWeek = "";
break;
case 2:
dayOfWeek = "";
break;
case 3:
dayOfWeek = "";
break;
case 4:
dayOfWeek = "";
break;
case 5:
dayOfWeek = "";
break;
case 6:
dayOfWeek = "";
break;
case 7:
dayOfWeek = "";
break;
}

return dayOfWeek;
}

//"년,월,일"을 붙여줌

public static String addDate(String day) {
int size = day.length();
StringBuffer sb = new StringBuffer(day);

if (size == 8) {
sb.insert(4, " ");
sb.insert(8, " ");
sb.insert(12, " ");
}
return sb.toString();
}

반응형

WRITTEN BY
아카이시

,