Example usage for java.text DateFormat parse

List of usage examples for java.text DateFormat parse

Introduction

In this page you can find the example usage for java.text DateFormat parse.

Prototype

public Date parse(String source) throws ParseException 

Source Link

Document

Parses text from the beginning of the given string to produce a date.

Usage

From source file:br.ufpb.dicomflow.integrationAPI.tools.ReadService.java

private static void configureFilterProperties(FilterIF filter, CommandLine cl)
        throws java.text.ParseException, NumberFormatException {
    if (cl.hasOption(FILTER_OPTION)) {

        filter = new SMTPFilter();

        if (cl.hasOption(INITIAL_DATE_OPTION)) {
            DateFormat formater = new SimpleDateFormat("dd/MM/aaaa");
            filter.setInitialDate(formater.parse(cl.getOptionValue(INITIAL_DATE_OPTION)));

        }//from  www . ja va  2 s  .  c  om

        if (cl.hasOption(FINAL_DATE_OPTION)) {
            DateFormat formater = new SimpleDateFormat("dd/MM/aaaa");
            filter.setInitialDate(formater.parse(cl.getOptionValue(FINAL_DATE_OPTION)));

        }

        if (cl.hasOption(SERVICE_TYPE_OPTION)) {
            Integer serviceType = Integer.parseInt(cl.getOptionValue(SERVICE_TYPE_OPTION));
            filter.setServiceType(serviceType);
        }

        if (cl.hasOption(ID_MESSAGE_OPTION)) {
            filter.setIdMessage(cl.getOptionValue(ID_MESSAGE_OPTION));
        }

    }

}

From source file:com.dianxin.imessage.common.util.DateUtil.java

/**
 * date//from   w  w w  . java 2 s .c o m
 *
 * @param date
 * @param pattern
 * @return
 */
public static Date toDate(String date, String pattern) throws ParseException {
    DateFormat dateFormat = new SimpleDateFormat(pattern);
    return dateFormat.parse(date);
}

From source file:DateUtil.java

/**
 * Parses given string according to specified locale and date style
 *
 * @param source    Source string to parse date from
 * @param locale    Locale to use for parsing date
 * @param dateStyle Date style//from w w w . jav a  2s . c o m
 * @return Date object corresponding to representation given in source string
 * @throws ParseException if given string could not be properly parsed according to given locale and style
 * @see java.text.DateFormat
 */
public static Date parseDate(String source, Locale locale, int dateStyle) throws ParseException {
    DateFormat formatter = DateFormat.getDateInstance(dateStyle, locale);
    return formatter.parse(source);
}

From source file:DateUtil.java

/**
 * Parses given string according to specified locale and time style
 *
 * @param source    Source string to parse time from
 * @param locale    Locale to use for parsing time
 * @param timeStyle Time style/*w  ww  .ja va 2 s  .co m*/
 * @return Time object corresponding to representation given in source string
 * @throws ParseException if given string could not be properly parsed according to given locale and style
 * @see java.text.DateFormat
 */
public static Date parseTime(String source, Locale locale, int timeStyle) throws ParseException {
    DateFormat formatter = DateFormat.getTimeInstance(timeStyle, locale);
    return formatter.parse(source);
}

From source file:eu.annocultor.converters.solr.SolrPeriodsTagger.java

static Date parseDate(String dateString, String affixToTryOnYearOnly) {
    try {/*w w w.j  a  v  a  2  s.co m*/
        if (dateString.length() == 4 && dateString.matches("\\d\\d\\d\\d")) {
            dateString += affixToTryOnYearOnly;
        }
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        if (StringUtils.isEmpty(dateString)) {
            return null;
        }
        return dateFormat.parse(dateString);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        return null;
    }
}

From source file:com.app.intuit.util.WebUtils.java

public static Date convertStringToDate(String requestedDateStr) {

    Date requestedDate;/*from   w w w .j  av  a2 s . co  m*/

    try {
        DateFormat formatter = new SimpleDateFormat("MMM DD, YYYY");

        requestedDate = (Date) formatter.parse(requestedDateStr);
    } catch (ParseException e) {
        return null;
    }

    return requestedDate;
}

From source file:com.naver.mage4j.core.util.PhpDateUtils.java

public static Date getFirstDayOfMinusMonth(String yyyyMM) throws ParseException {
    DateFormat dateFormat = new SimpleDateFormat("yyyyMM");
    Date date = dateFormat.parse(yyyyMM);

    return new DateMidnight(date).minusMonths(1).withDayOfMonth(1).toDate();
}

From source file:com.naver.mage4j.core.util.PhpDateUtils.java

public static Date getLastDayOfMinusMonth(String yyyyMM) throws ParseException {
    DateFormat dateFormat = new SimpleDateFormat("yyyyMM");
    Date date = dateFormat.parse(yyyyMM);

    return new DateMidnight(date).withDayOfMonth(1).minusDays(1).toDate();
}

From source file:com.modeln.batam.connector.wrapper.Commit.java

public static Commit fromJSON(JSONObject obj) {
    String buildId = (String) obj.get("build_id");
    String buildName = (String) obj.get("build_name");
    String commitId = (String) obj.get("commit_id");
    String url = (String) obj.get("url");
    String author = (String) obj.get("author");
    String dateCommitted = (String) obj.get("date_committed");
    DateFormat dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy Z");
    try {/*from  ww  w .ja  va  2  s  .  c  o  m*/
        return new Commit(buildId, buildName, commitId, url, author,
                dateCommitted == null ? null : dateFormat.parse(dateCommitted));
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:DateUtil.java

/**
 * Parses given string according to specified locale and date and time styles
 *
 * @param source    Source string to parse date and time from
 * @param locale    Locale to use for parsing date and time
 * @param dateStyle Date style/*from w w w.  ja va  2s .c om*/
 * @param timeStyle Time style
 * @return Date object corresponding to representation given in source string
 * @throws ParseException if given string could not be properly parsed according to given locale and style
 * @see java.text.DateFormat
 */
public static Date parseDateTime(String source, Locale locale, int dateStyle, int timeStyle)
        throws ParseException {
    DateFormat formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
    return formatter.parse(source);
}