Example usage for org.apache.commons.lang3.time DateUtils parseDate

List of usage examples for org.apache.commons.lang3.time DateUtils parseDate

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateUtils parseDate.

Prototype

public static Date parseDate(final String str, final String... parsePatterns) throws ParseException 

Source Link

Document

Parses a string representing a date by trying a variety of different parsers.

The parse will try each parse pattern in turn.

Usage

From source file:com.tala.enterprise.talabank.commons.DateManager.java

public static Date getDate(String format) throws ParseException {
    DateFormat dateFormat = new SimpleDateFormat(format);
    Date date = new Date();
    //return dateFormat.parse(date.toString());
    return DateUtils.parseDate(dateFormat.format(date), format);
}

From source file:com.mmone.gpdati.allotment.reader.AvailCrud.java

public static void saveAllotment(XmlRpcClient client, Integer hotelCode, String startDt, String endDt,
        Integer roomId, int bookingLimit) throws Exception {
    Date sdt = DateUtils.parseDate(startDt, dateParsers);
    Date edt = DateUtils.parseDate(endDt, dateParsers);

    saveAllotment(client, hotelCode, sdt, edt, roomId, bookingLimit);
}

From source file:com.my373.common.util.MyDateUtils.java

/**
 * String to Date,RuntimeException/*w ww . j  a v a 2 s  . c  o m*/
 * 
 * @param str
 * @param parsePatterns
 * @return
 */
public static Date parseDate(final String str, final String... parsePatterns) {
    Date date = null;
    try {
        date = DateUtils.parseDate(str, parsePatterns);
    } catch (ParseException e) {
        throw new RuntimeException("?");
    }
    return date;
}

From source file:io.cloudslang.content.azure.utils.DateUtilities.java

@NotNull
public static Date parseDate(@NotNull final String date) throws ParseException {
    return DateUtils.parseDate(date, "MM/dd/yyyy h:mm a");
}

From source file:com.tala.enterprise.talabank.commons.DateManager.java

public static Date parseDateFromStringToDate(String date, String format) throws ParseException {
    return DateUtils.parseDate(date, format);
}

From source file:net.larry1123.elec.util.logger.FileManager.java

public static long getSplitTime() {
    long set = System.currentTimeMillis();
    try {/*from   w  w  w  .  j  a va  2 s  .c  om*/
        Date currentTime = DateUtils.parseDate(getDateFormatFromMilli(System.currentTimeMillis()),
                DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern());
        Date currentSplit = DateUtils.parseDate(getDateFormatFromMilli(getConfig().getCurrentSplit()),
                DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern());
        Date test;
        switch (getConfig().getSplit()) {
        case HOUR:
            test = DateUtils.addHours(currentTime, 1);
            test = DateUtils.setMinutes(test, 0);
            test = DateUtils.setSeconds(test, 0);
            test = DateUtils.setMilliseconds(test, 0);
            if (test.after(currentSplit)) {
                set = getConfig().getCurrentSplit();
            }
            break;
        case DAY:
            if (!DateUtils.isSameDay(currentTime, currentSplit)) {
                set = getConfig().getCurrentSplit();
            }
            break;
        case WEEK:
            test = DateUtils.ceiling(currentTime, Calendar.WEEK_OF_MONTH);
            if (test.after(currentSplit)) {
                set = getConfig().getCurrentSplit();
            }
            break;
        case MONTH:
            test = DateUtils.ceiling(currentTime, Calendar.MONTH);
            if (test.after(currentSplit)) {
                set = getConfig().getCurrentSplit();
            }
            break;
        case NONE:
        default:
            set = 0;
            break;
        }
    } catch (ParseException e) {
        set = 0;
    }
    return set;
}

From source file:com.beginner.core.utils.DateUtil.java

public static Date parseDate(Object str) {
    if (str == null) {
        return null;
    }/*from   w  ww  .ja va2s. com*/
    try {
        return DateUtils.parseDate(str.toString(), PARSE_PATTERNS);
    } catch (ParseException e) {
        return null;
    }
}

From source file:com.thruzero.common.core.utils.DateTimeUtilsExt.java

/**
 * Return the parsed Date, using the given {@code parsePatterns}. If the value is null, then null is returned;
 * otherwise, each of the given patterns will be used to parse the value as a Date, until a successful parse or all
 * patterns have been exhausted, in which case a ParseException is thrown.
 *
 * @throws ParseException/*from   w w  w  .j a v  a2s  .co  m*/
 */
public static Date stringToDate(final String value, final Date defaultValue, final String... parsePatterns) {
    Date result = null;

    if (value != null) {
        try {
            result = DateUtils.parseDate(value, parsePatterns);
        } catch (ParseException e) {
            // use the default value if no match was found
        }
    }

    if (result == null) {
        result = defaultValue;
    }

    return result;
}

From source file:io.wcm.tooling.commons.contentpackagebuilder.ValueConverterTest.java

@Before
public void setUp() throws Exception {
    underTest = new ValueConverter();
    sampleDate = DateUtils.parseDate("05.09.2010 15:10:20", "dd.MM.yyyy HH:mm:ss");
}

From source file:com.mxep.web.common.persistence.SearchFilter.java

/**
 * searchParamskey?OPERATOR_FIELDNAME/*from   w ww. ja  v  a 2s .  c o m*/
 */
public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) {
    Map<String, SearchFilter> filters = Maps.newHashMap();

    for (Entry<String, Object> entry : searchParams.entrySet()) {
        // 
        String key = entry.getKey();
        Object value = entry.getValue();
        if (value != null && StringUtils.isBlank(value.toString())) {
            continue;
        }

        // operatorfiledAttribute
        String[] names = StringUtils.split(key, "_");
        if (names.length < 2) {
            throw new IllegalArgumentException(key + " is not a valid search filter name");
        }
        String filedName = "";
        for (int i = 1; i < names.length; i++) {
            filedName += names[i];
            if ((i + 1) < names.length) {
                filedName += ".";
            }
        }

        Operator operator = getOperator(names[0]);
        if (null == operator) {
            continue;
        }

        // searchFilter
        if (isValidDate(value.toString())) {
            try {
                Date date = DateUtils.parseDate((String) value, "yyyy-MM-dd");
                // ?
                if (operator.equals(Operator.LT) || operator.equals(Operator.LTE)) {
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(date);
                    cal.add(Calendar.DAY_OF_YEAR, 1);
                    date = cal.getTime();
                }
                // ????
                if (operator.equals(Operator.GT) || operator.equals(Operator.GTE)) {
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(date);
                    date = cal.getTime();
                }
                value = date;
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (isValidDateTime(value.toString())) {
            try {
                Date date = DateUtils.parseDate((String) value, "yyyy-MM-dd HH:mm:ss");
                value = date;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        // searchFilter
        SearchFilter filter = new SearchFilter(filedName, operator, value);
        filters.put(key, filter);
    }

    return filters;
}