날짜포맷 메소드 수정

master
mjkhan21 8 months ago
parent 728d527752
commit 759a2d4898

@ -1,6 +1,8 @@
package cokr.xit.foundation.data;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import cokr.xit.foundation.AbstractComponent;
@ -28,15 +30,19 @@ public class DataFormat extends AbstractComponent {
public static final String yyyy_mm_dd(Object obj) {
if (isEmpty(obj)) return "";
String str = obj.toString();
int length = str.length(),
pos = length - 2;
if (obj instanceof String) {
String str = obj.toString();
int length = str.length(),
pos = length - 2;
String
day = str.substring(pos),
month = str.substring(pos = pos - 2, pos + 2),
year = str.substring(0, pos);
return String.format("%s-%s-%s", year, month, day);
String
day = str.substring(pos),
month = str.substring(pos = pos - 2, pos + 2),
year = str.substring(0, pos);
return String.format("%s-%s-%s", year, month, day);
} else {
return yyyy_mm_dd_hh_mm_ss(obj).substring(0, 10);
}
}
/**HHmmss HH:mm:ss .
@ -46,37 +52,48 @@ public class DataFormat extends AbstractComponent {
public static final String hh_mm_ss(Object obj) {
if (isEmpty(obj)) return "";
String str = obj.toString();
int length = str.length(),
pos = length - 2;
if (obj instanceof String) {
String str = obj.toString();
int length = str.length(),
pos = length - 2;
String
ss = str.substring(pos),
mm = str.substring(pos = pos - 2, pos + 2),
hh = str.substring(0, pos);
return String.format("%s:%s:%s", hh, mm, ss);
String
ss = str.substring(pos),
mm = str.substring(pos = pos - 2, pos + 2),
hh = str.substring(0, pos);
return String.format("%s:%s:%s", hh, mm, ss);
} else {
return yyyy_mm_dd_hh_mm_ss(obj).substring(11);
}
}
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**yyyyMMddHHmmss, yyMMddHHmmss yyyy-MM-dd HH:mm:ss .
* @param obj yyyyMMddHHmmss, yyMMddHHmmss
* @return yyyy-MM-dd HH:mm:ss
*/
public static final String yyyy_MM_dd_HH_mm_ss(Object obj) {
public static final String yyyy_mm_dd_hh_mm_ss(Object obj) {
if (isEmpty(obj)) return "";
String str = obj.toString();
int length = str.length(),
pos = length - 6;
try {
String
date = str.substring(0, pos),
time = str.substring(pos);
return yyyy_mm_dd(date) + " " + hh_mm_ss(time);
} catch (Exception e) {
return str;
}
if (obj instanceof String) {
String str = obj.toString();
int length = str.length(),
pos = length - 6;
try {
String
date = str.substring(0, pos),
time = str.substring(pos);
return yyyy_mm_dd(date) + " " + hh_mm_ss(time);
} catch (Exception e) {
return str;
}
} else if (obj instanceof Date)
return dateFormat.format((Date)obj);
else
throw new IllegalArgumentException(obj + " is not a Date");
}
private static final DecimalFormat numberFormat = new DecimalFormat("#,##0.00");

Loading…
Cancel
Save