1、时间格式
2018-12-14T10:00:00Z
复制代码
将以上格式的字符串转为普通格式:
/**
* 2018-12-14T10:00:00Z
*
* @param strTime
* @return
* @throws ParseException
*/
public static String getTime(String strTime) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = formatter.parse(strTime);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = sdf.format(date);
return time;
}
复制代码
/**
* 2018-12-14T10:00:00Z
*
* @param strTime
* @return
* @throws ParseException
*/
public static Date getDate(String strTime) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = formatter.parse(strTime);
return date;
}
/**
* @param date
* @return
* @throws ParseException
*/
public static String getTime(Date date) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = sdf.format(date);
return time;
}
/**
* 获取数组中出现次数最多的元素
* @param strings
* @return
*/
public static String getMaxString(List<String> strings) {
HashMap<String, Integer> map = new HashMap<>();
for (String string : strings) {
if (map.containsKey(string)) {
int temp = map.get(string);
map.put(string, temp + 1);
} else {
map.put(string, 1);
}
}
Collection<Integer> collection = map.values();
int maxCount = Collections.max(collection);
String maxString = "";
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (maxCount == entry.getValue()) {
maxString = entry.getKey();
}
}
return maxString;
}
复制代码