/** Attempt to parse the Date from a Date-based header, primarily If-Modified-Since */ public static Date fromIfModifiedSince( String headerValue ) { Date moded = null; if ( !StringUtils.isEmpty( headerValue ) ) { try { moded = DateUtils.parseDate( headerValue, DEFAULT_PATTERNS ); } catch ( ParseException pe ) { logger.error( "Could not parse date format from If-Modified-Since header: {}", headerValue ); } } return moded; }
public static long toDate(final Object obj) throws ParseException { if (obj instanceof Date) { return ((Date) obj).getTime(); } try { return DateUtils.parseDate(obj.toString().toUpperCase(), DATE_PATTERNS).getTime(); } catch (final java.text.ParseException e) { throw new ParseException(e.getMessage()); } }
/** * Attempts to parse an input value using one of several patterns. * * @param value String to parse. * @param patterns Patterns to be tried in succession until parsing succeeds. * @return The resulting date value. * @throws ParseException Date parsing exception. */ public static Date parseDate(String value, String... patterns) throws ParseException { return DateUtils.parseDate(value, patterns); }
/** * Attempts to parse an input value using one of several patterns. * * @param value String to parse. * @param patterns Patterns to be tried in succession until parsing succeeds. * @return The resulting date value. * @throws ParseException Date parsing exception. */ public static Date parseDate(String value, String... patterns) throws ParseException { return DateUtils.parseDate(value, patterns); }
/** * {@inheritDoc} * * Delegate the parse method to the thread safe {@link FastDateFormat} * class. */ @Override public Date parse( String source ) throws ParseException { return DateUtils.parseDate( source, _parsePatterns ); }
/** * #func 把字符串转化为日期<br> * #desc 在此添加实现相关说明 * * @author hedan * @version 4.0 */ public static Date parseDate(String date, String pattern) { try { return org.apache.commons.lang.time.DateUtils.parseDate(date, new String[] {pattern}); } catch (ParseException e) { return null; } }
/** * #func 把字符串转化为日期<br> * #desc 使用yyyy-MM-dd作为样式 * * @author hedan * @version 4.0 */ public static Date parseDate(String date) { if (date == null) { return null; } try { return org.apache.commons.lang.time.DateUtils.parseDate(date, new String[] {DSP_DEFAULT_TIME_FORMAT}); } catch (ParseException e) { return null; } }
public XMLGregorianCalendar parseDateTime(String format, String stringDate) throws ParseException { if (format == null || stringDate == null) { return null; } String[] formats = new String[]{format}; Date date = DateUtils.parseDate(stringDate, formats); if (date == null) { return null; } return XmlTypeConverter.createXMLGregorianCalendar(date); }
String str = "06th Oct 2013"; String[] strArrFormat = {"dd'st' MMM yyyy","dd'nd' MMM yyyy","dd'th' MMM yyyy","dd'rd' MMM yyyy"}; DateUtils tmpDU = new DateUtils(); System.out.print("" + tmpDU.parseDate(str,strArrFormat));
/** * 指定した文字列形式の日付が、日付形式なのかチェックする. * @param src チェック対象の日付文字列 * @return true:日付形式、false:日付形式ではない */ private Boolean validISO8601b(final String src) { String[] patterns = {"yyyy-MM-dd'T'HH:mm:ss.SSS"}; try { org.apache.commons.lang.time.DateUtils.parseDate(src, patterns); } catch (ParseException e) { return false; } return true; }
public static String tryBuildYearlyPattern(String value) { String valueSuffix = StringUtils.substring(value, value.length() - 4); try { DateUtils.parseDate(valueSuffix, new String[]{"yyyy"}); return StringUtils.substring(value, 0, value.length() - 4) + YEAR_SUFFIX; } catch (ParseException e) { } return value; }
/** * 指定した文字列形式の日付が、日付形式なのかチェックする. * @param src チェック対象の日付文字列 * @return true:日付形式、false:日付形式ではない */ private Boolean validISO8601a(final String src) { // FastDateFormat fastDateFormat = // org.apache.commons.lang.time.DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT; String[] patterns = {"yyyy-MM-dd'T'HH:mm:ss'Z'"}; try { org.apache.commons.lang.time.DateUtils.parseDate(src, patterns); } catch (ParseException e) { return false; } return true; }
private static XMLGregorianCalendar magicDateTimeParse(String stringDate) { try { return XmlTypeConverter.createXMLGregorianCalendar(stringDate); } catch (IllegalArgumentException e) { // No XML format. This is still quite OK. It we will try other formats ... } Date date; try { date = DateUtils.parseDate(stringDate, DATE_FORMATS); } catch (ParseException e) { throw new IllegalArgumentException(e.getMessage(), e); } return XmlTypeConverter.createXMLGregorianCalendar(date); }
public static String tryBuildMonthlyPattern(String value) { try { String valueSuffix = StringUtils.substring(value, value.length() - 6); DateUtils.parseDate(valueSuffix, new String[]{"yyyyMM"}); return StringUtils.substring(value, 0, value.length() - 6) + MONTH_SUFFIX; } catch (ParseException e) { } try { String valueSuffix = StringUtils.substring(value, value.length() - 7); DateUtils.parseDate(valueSuffix, new String[]{"yyyy-MM", "yyyy/MM", "yyyy.MM"}); return StringUtils.substring(value, 0, value.length() - 7) + MONTH_SUFFIX; } catch (ParseException e) { } return value; }
public static SequenceNumber bytes2SequenceN(byte[] bytes) { long nodeIds = ByteBuffer.wrap(Arrays.copyOfRange(bytes, 0, 4)).getInt() & 0xFFFFFFFFL; //sgip协议里时间不带年份信息,这里判断下年份信息 String year = DateFormatUtils.format(CachedMillisecondClock.INS.now(), "yyyy"); String t = String.format("%1$s%2$010d",year, ByteBuffer.wrap(Arrays.copyOfRange(bytes, 4, 8)).getInt() & 0xFFFFFFFFL); Date d ; try { d = DateUtils.parseDate(t, datePattern); //如果正好是年末,这个时间有可能差一年,则必须取上一年 //这里判断取200天,防止因不同主机时间不同步造成误差 if(d.getTime() - CachedMillisecondClock.INS.now() > 86400000L * 200){ d = DateUtils.addYears(d, -1); } } catch (ParseException e) { d = new Date(); e.printStackTrace(); } long sequenceId = ByteBuffer.wrap(Arrays.copyOfRange(bytes, 8, 12)).getInt() & 0xFFFFFFFFL; SequenceNumber sn = new SequenceNumber(d.getTime(),nodeIds,sequenceId); return sn; }
public static boolean isYearlyMatch(String pattern, String value) { if (!StringUtils.endsWith(pattern, YEAR_SUFFIX)) { throw new ValidationException("the pattern must end with " + YEAR_SUFFIX); } String valueSuffix = StringUtils.substring(value, value.length() - 4); String valuePrefix = StringUtils.substring(value, 0, value.length() - 4); if (StringUtils.substringBeforeLast(pattern, YEAR_SUFFIX).equals(valuePrefix)) { try { DateUtils.parseDate(valueSuffix, new String[]{"yyyy"}); return true; } catch (ParseException e) { } } return false; }
public static boolean isMonthlyMatch(String pattern, String value) { if (!StringUtils.endsWith(pattern, MONTH_SUFFIX)) { throw new ValidationException("the pattern must end with " + MONTH_SUFFIX); } String patternPrefix = StringUtils.substringBeforeLast(pattern, MONTH_SUFFIX); String valueSuffix = StringUtils.substring(value, value.length() - 6); String valuePrefix = StringUtils.substring(value, 0, value.length() - 6); if (patternPrefix.equals(valuePrefix)) { try { DateUtils.parseDate(valueSuffix, new String[]{"yyyyMM"}); return true; } catch (ParseException e) { } } valueSuffix = StringUtils.substring(value, value.length() - 7); valuePrefix = StringUtils.substring(value, 0, value.length() - 7); if (patternPrefix.equals(valuePrefix)) { try { DateUtils.parseDate(valueSuffix, new String[]{"yyyy-MM", "yyyy/MM", "yyyy.MM"}); return true; } catch (ParseException e) { } } return false; }
@Override public Boolean resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException { String studentId = (String) resolvedPrereqs.get(RulesExecutionConstants.STUDENT_ID_TERM_NAME); Date currentDate = (Date) resolvedPrereqs.get(RulesExecutionConstants.CURRENT_DATE_TERM_NAME); Entity entity = identityService.getEntity(studentId); Date deceasedDate = null; if(entity.getBioDemographics().getDeceasedDate() != null) { try { deceasedDate = DateUtils.parseDate(entity.getBioDemographics().getDeceasedDate(), new String[]{EntityBioDemographicsContract.DECEASED_DATE_FORMAT}); } catch (ParseException e) { throw new TermResolutionException(e.getMessage(), this, parameters, e); } } if(deceasedDate != null) { return deceasedDate.before(currentDate); } return false; } }
/** * * @param msgIds */ public SequenceNumber(MsgId msgIds) { String strmsgid = msgIds.toString(); setNodeIds(msgIds.getGateId()); //sgip协议里时间不带年份信息,这里判断下年份信息 String year = DateFormatUtils.format(CachedMillisecondClock.INS.now(), "yyyy"); String t = String.format("%1$s%2$s",year, strmsgid.substring(0, 10)); Date d; try { d = DateUtils.parseDate(t, datePattern); //如果正好是年末,这个时间有可能差一年,则必须取上一年 //这里判断取200天,防止因不同主机时间不同步造成误差 if(d.getTime() - CachedMillisecondClock.INS.now() > 86400000L * 200){ d = DateUtils.addYears(d, -1); } } catch (ParseException e) { e.printStackTrace(); d = new Date(); } setTimestamp(d.getTime()); setSequenceId(msgIds.getSequenceId()); } /**
/** * @return a new VelocityFunctions instance for the given patientId */ private VelocityFunctions setupFunctionsForPatient(Integer patientId) throws Exception { HtmlForm htmlform = new HtmlForm(); Form form = new Form(); form.setEncounterType(new EncounterType(1)); htmlform.setForm(form); htmlform.setDateChanged(new Date()); htmlform.setXmlData("<htmlform></htmlform>"); Patient p = new Patient(patientId); String[] datePattern = {"yyyy.MM.dd"}; p.setBirthdate(DateUtils.parseDate("1970.01.01",datePattern )); measureAgeInDaysAndMonths(new Date(), p.getBirthdate()); FormEntrySession session = new FormEntrySession(p, htmlform, null); return new VelocityFunctions(session); }