public static String dateToString(Date date, String formatString) {
SimpleDateFormat format = new SimpleDateFormat(formatString);
return format.format(date);
}
public static Date stringToDate(String dateString, String formatString) {
try {
SimpleDateFormat format = new SimpleDateFormat(formatString);
return format.parse(dateString);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static String formatDateString(
String dateString,
String formatString) {
try {
SimpleDateFormat format = new SimpleDateFormat(formatString);
return format.format(format.parse(dateString));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Date formatStringToDate(
String dateString,
String formatString) {
try {
SimpleDateFormat format = new SimpleDateFormat(formatString);
//dateString = format.format(formatString);
//return java.sql.Date.valueOf(dateString);
dateString = format.format(format.parse(dateString));
return java.sql.Date.valueOf(dateString);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Date getTimeNeglectDate(Date date) {
String timeString = Util.dateToString(date, Constants.TIMEFORMAT);
return Util.stringToDate(timeString, Constants.TIMEFORMAT);
}
public static Date getDateNeglectTime(Date date) {
String dateString = Util.dateToString(date, Constants.DATEFORMAT);
return Util.stringToDate(dateString, Constants.DATEFORMAT);
}
public static long intervalminute(Date fromdate, Date todate) {
return (todate.getTime() - fromdate.getTime()) / (1000 * 60);
}
public static Map getMessageMap(
String[] keys,
String[] valuesKey,
MessageSource messageSource,
Locale locale) {
String[] values = new String[valuesKey.length];
for (int i = 0; i < valuesKey.length; i++) {
values[i] = messageSource.getMessage(valuesKey[i], null, locale);
}
return Util.getProperMap(keys, values);
}
public static Map getProperMap(String[] keys, String[] values) {
Map properMap = new HashMap();
for (int i = 0; i < keys.length; i++) {
properMap.put(keys[i], values[i]);
}
return properMap;
}
public static float getFormatNum(float number) {
try {
return getFormatNum(number, Constants.NUMBERFORMAT);
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
}
public static float getFormatNum(float number, String format)
throws ParseException {
DecimalFormat decimalFormat = new DecimalFormat(format);
return Float.valueOf(decimalFormat.format(number)).floatValue();
}
public static String getDefaultEndTime() {
return getDefaultEndTime(Constants.DATEFORMAT);
}
public static String getDefaultStartTime(int calendarUnit) {
return getDefaultStartTime(calendarUnit, Constants.DATEFORMAT);
}
public static String getDefaultEndTime(String format) {
Calendar day = Calendar.getInstance();
Date today = day.getTime();
return Util.dateToString(today, format);
}
public static String getDefaultStartTime(int calendarUnit, String format) {
Calendar day = Calendar.getInstance();
day.add(calendarUnit, -1);
Date aMonthAgo = day.getTime();
return Util.dateToString(aMonthAgo, format);
}
/** 使用例子
* Comparator comparator = new BeanComparator("shiftinfoid");
* comparator = ComparatorUtils.reversedComparator(comparator);
* Collections.sort(shiftInfoList, comparator);
* */
public static List sort(List list, String sort, String sortType) {
if (null != sort && null != sortType) {
Comparator comparator = new BeanComparator(sort);
if ("desc".equals(sortType)) {
comparator = ComparatorUtils.reversedComparator(comparator);
}
Collections.sort(list, comparator);
}
return list;
}
SimpleDateFormat format = new SimpleDateFormat(formatString);
return format.format(date);
}
public static Date stringToDate(String dateString, String formatString) {
try {
SimpleDateFormat format = new SimpleDateFormat(formatString);
return format.parse(dateString);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static String formatDateString(
String dateString,
String formatString) {
try {
SimpleDateFormat format = new SimpleDateFormat(formatString);
return format.format(format.parse(dateString));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Date formatStringToDate(
String dateString,
String formatString) {
try {
SimpleDateFormat format = new SimpleDateFormat(formatString);
//dateString = format.format(formatString);
//return java.sql.Date.valueOf(dateString);
dateString = format.format(format.parse(dateString));
return java.sql.Date.valueOf(dateString);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Date getTimeNeglectDate(Date date) {
String timeString = Util.dateToString(date, Constants.TIMEFORMAT);
return Util.stringToDate(timeString, Constants.TIMEFORMAT);
}
public static Date getDateNeglectTime(Date date) {
String dateString = Util.dateToString(date, Constants.DATEFORMAT);
return Util.stringToDate(dateString, Constants.DATEFORMAT);
}
public static long intervalminute(Date fromdate, Date todate) {
return (todate.getTime() - fromdate.getTime()) / (1000 * 60);
}
public static Map getMessageMap(
String[] keys,
String[] valuesKey,
MessageSource messageSource,
Locale locale) {
String[] values = new String[valuesKey.length];
for (int i = 0; i < valuesKey.length; i++) {
values[i] = messageSource.getMessage(valuesKey[i], null, locale);
}
return Util.getProperMap(keys, values);
}
public static Map getProperMap(String[] keys, String[] values) {
Map properMap = new HashMap();
for (int i = 0; i < keys.length; i++) {
properMap.put(keys[i], values[i]);
}
return properMap;
}
public static float getFormatNum(float number) {
try {
return getFormatNum(number, Constants.NUMBERFORMAT);
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
}
public static float getFormatNum(float number, String format)
throws ParseException {
DecimalFormat decimalFormat = new DecimalFormat(format);
return Float.valueOf(decimalFormat.format(number)).floatValue();
}
public static String getDefaultEndTime() {
return getDefaultEndTime(Constants.DATEFORMAT);
}
public static String getDefaultStartTime(int calendarUnit) {
return getDefaultStartTime(calendarUnit, Constants.DATEFORMAT);
}
public static String getDefaultEndTime(String format) {
Calendar day = Calendar.getInstance();
Date today = day.getTime();
return Util.dateToString(today, format);
}
public static String getDefaultStartTime(int calendarUnit, String format) {
Calendar day = Calendar.getInstance();
day.add(calendarUnit, -1);
Date aMonthAgo = day.getTime();
return Util.dateToString(aMonthAgo, format);
}
/** 使用例子
* Comparator comparator = new BeanComparator("shiftinfoid");
* comparator = ComparatorUtils.reversedComparator(comparator);
* Collections.sort(shiftInfoList, comparator);
* */
public static List sort(List list, String sort, String sortType) {
if (null != sort && null != sortType) {
Comparator comparator = new BeanComparator(sort);
if ("desc".equals(sortType)) {
comparator = ComparatorUtils.reversedComparator(comparator);
}
Collections.sort(list, comparator);
}
return list;
}