List of usage examples for org.apache.commons.lang.time DateUtils parseDate
public static Date parseDate(String str, String... parsePatterns) throws ParseException
Parses a string representing a date by trying a variety of different parsers.
The parse will try each parse pattern in turn.
From source file:com.kamike.misc.MiscDateUtils.java
public static Date getDate(String value) { if ("".endsWith(value) || value == null) { return new Date(System.currentTimeMillis()); }/*from ww w .j a v a 2s. c om*/ try { return DateUtils.parseDate(value, DATE_PATTERN); } catch (ParseException ex) { Logger.getLogger(MiscDateUtils.class.getName()).log(Level.SEVERE, null, ex); return new Date(System.currentTimeMillis()); } }
From source file:com.reizes.shiva.utils.DateUtil.java
/** * ?? ? //from www. j av a 2 s .c o m * @param data * @return Date * @since 2.1.5 */ public static Date parse(String data) { try { return DateUtils.parseDate(data, new String[] { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss" }); } catch (ParseException e) { return null; } }
From source file:com.smartitengineering.cms.ws.common.utils.Utils.java
public static Date parseStringAsDate(String dateString) throws ParseException { return DateUtils.parseDate(dateString, new String[] { DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern() }); }
From source file:com.smartitengineering.cms.api.impl.content.DateTimeFieldValueImpl.java
static MutableDateTimeFieldValue valueOf(String value) throws ParseException { DateTimeFieldValueImpl fieldValue = new DateTimeFieldValueImpl(); fieldValue.setValue(DateUtils.parseDate(value, new String[] { DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern() })); return fieldValue; }
From source file:net.duckling.ddl.util.AoneTimeUtils.java
public static Date parseDateTime(String textDate) { try {//from ww w. ja v a 2 s . c o m return DateUtils.parseDate(textDate, new String[] { DATE_TIME_PATTERN }); } catch (ParseException e) { log.error("parse date time error for input " + textDate, e); } return null; }
From source file:com.nbp.nmp.benefit.common.CommonDataHandleUtil.java
/** * ? ? ? //from w w w . j a v a2 s. c o m * @param date * @param fromFormatString * @param toFormatString * @return */ public static String stringDateFormatter(String date, String fromFormatString, String toFormatString) { String[] fromParttern = { fromFormatString }; FastDateFormat toFormatter = FastDateFormat.getInstance(toFormatString); Date fromDate = null; try { fromDate = DateUtils.parseDate(date, fromParttern); } catch (Exception e) { return ""; } return toFormatter.format(fromDate); }
From source file:com.smartitengineering.cms.spi.impl.hbase.Utils.java
public static Date toDate(final byte[] dateBytes) { try {//from ww w. j a v a 2s .co m String dateString = StringUtils.newStringUtf8(dateBytes); return DateUtils.parseDate(dateString, new String[] { DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern() }); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:com.appleframework.monitor.model.TimeRangeTest.java
public void test_start() throws Exception { timeRange.setNow(DateUtils.parseDate("2011-11-11 00:00", new String[] { DATE_FORMAT })); timeRange.setLast(1);/* www .j a va 2 s .c om*/ timeRange.setUnit(Calendar.HOUR); assertEquals("2011-11-10 23:00", sdf.format(timeRange.getStart())); timeRange.setUnit(Calendar.DATE); assertEquals("2011-11-10 00:00", sdf.format(timeRange.getStart())); }
From source file:net.duckling.ddl.util.AoneTimeUtils.java
public static Date parseDate(String textDate) { try {//from w w w .j a v a2s .co m return DateUtils.parseDate(textDate, new String[] { DATE_PATTERN }); } catch (ParseException e) { log.error("parse date error for input " + textDate, e); } return null; }
From source file:com.lingxiang2014.DateEditor.java
@Override public void setAsText(String text) { if (text == null) { setValue(null);//from w ww .j a va2 s . c om } else { String value = text.trim(); if (emptyAsNull && "".equals(value)) { setValue(null); } else { try { setValue(DateUtils.parseDate(value, CommonAttributes.DATE_PATTERNS)); } catch (ParseException e) { setValue(null); } } } }