private long parse(final String dateVal) { for (int i = 0; i < _dateReceive.length; i++) { if (_dateReceive[i] == null) { _dateReceive[i] = new SimpleDateFormat(__dateReceiveFmt[i], Locale.US); _dateReceive[i].setTimeZone(__GMT); } try { Date date = (Date) _dateReceive[i].parseObject(dateVal); return date.getTime(); } catch (java.lang.Exception e) { // LOG.ignore(e); } } if (dateVal.endsWith(" GMT")) { final String val = dateVal.substring(0, dateVal.length() - 4); for (SimpleDateFormat element : _dateReceive) { try { Date date = (Date) element.parseObject(val); return date.getTime(); } catch (java.lang.Exception e) { // LOG.ignore(e); } } } return -1; }
@SuppressWarnings("unchecked") @Override public Object convertValue(Map<String, Object> context, Object value, Class toType) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { if (toType == Date.class) { // 当字符串向Date类型转换时 String[] params = (String[]) value; return sdf.parseObject(params[0]); } else if (toType == String.class) { // 当Date转换成字符串时 Date date = (Date) value; return sdf.format(date); } } catch (java.text.ParseException e) { e.printStackTrace(); } return null; }
@Override public Object[] getSections() { Object[] sections = new Object[mSeparatorsSet.size()]; List<String> entries = new ArrayList<String>(mSeparatorsSet.values()); for (int i = 0; i < entries.size(); i++) { try { sections[i] = reallyShortFormat.format(fullDateFormat.parse(entries.get(i))); if (sections[i].toString().length() > 4) { sections[i] = new SimpleDateFormat("d.").format(fullDateFormat.parseObject(entries.get(i))); } } catch (Exception e) { sections[i] = entries.get(i); } } return sections; }
@Override public Object stringToValue(String text) throws ParseException { return dateFormatter.parseObject(text); }
public static Date parseDate(String dateString, String format) throws ParseException { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); return (Date) simpleDateFormat.parseObject(dateString); }