public static Date stringToDate(String dateStr) {
Date date = null;
if (StringUtils.isNotBlank(dateStr)) {
try {
dateStr = URLDecoder.decode(dateStr, "UTF-8");
date = df.parse(dateStr);
} catch (Exception e) {
throw new RRException("日期格式转换异常!");
}
}
return date;
}
/**
* 字符串转换成日期
* @param strDate 日期字符串
* @param pattern 日期的格式,如:DateUtils.DATE_TIME_PATTERN
*/
public static Date stringToDate(String strDate, String pattern) {
if (StringUtils.isBlank(strDate)){
return null;
}
DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
return fmt.parseLocalDateTime(strDate).toDate();
}
第一种:
Date dtTimespan1 = DateUtils.stringToDate(timeStr);
long passSec1 = dtTimespan1.getTime();
第二种:
Date dtTimespan2 = DateUtils.stringToDate(timeStr,"yyyy-MM-dd HH:mm:ss");
long passSec2 = dtTimespan1.getTime()
第一种转化在压测试时生成的时间撮会有异常,或大或小
第一种转化在压测时容易导致网络IO问题
可能是URLDecoder.decode导致了上述问题
第二种正常