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:Main.java

public static Date parse(String fullDate, Locale locale) throws ParseException {
    DateFormat format = new SimpleDateFormat(IN_FORMAT, locale);

    return format.parse(fullDate);
}

From source file:Main.java

public static Date stringToDateTime(String str, String format) {
    DateFormat df = new SimpleDateFormat(format);
    try {/*from   w  ww . ja  v  a 2s . c o  m*/
        return df.parse(str);
    } catch (ParseException e) {
        return null;
    }
}

From source file:Main.java

public static Date parseToDate(String s) throws ParseException {
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    return format.parse(s);
}

From source file:Main.java

public static Date getDate(String dateString) {
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    try {/*from   ww w. j ava  2  s. com*/
        return format.parse(dateString);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static String bigTime(String date1, String date2, String format) {
    DateFormat dateFormat = new SimpleDateFormat(format);
    try {/*from  w w  w. jav a 2  s . c  om*/
        if (dateFormat.parse(date1).compareTo(dateFormat.parse(date2)) == 1) {
            return date1;
        } else {
            return date2;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static Date stringToDate4(String date) throws ParseException {

    DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
    Date _date = format.parse(date);
    return _date;

}

From source file:Main.java

public static Date parseDateToString(String inputDate, String datePattern) {
    DateFormat dateFormat = new SimpleDateFormat(datePattern);
    try {//from   ww w  . ja  va2  s . co m
        return dateFormat.parse(inputDate);
    } catch (ParseException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

/**
 * convert from 'String' format into 'Date' format
 * @param String sDate/*  w w  w.  j  a  va 2 s  .c  om*/
 * @param String dateFormat
 * @return
 */
@SuppressWarnings("deprecation")
public static Date StringToDate(String sDate, String dateFormat) {
    Date date = null;

    try {
        DateFormat formatter = new SimpleDateFormat(dateFormat);
        date = formatter.parse(sDate);
    } catch (Exception e) {
        date = new Date(1900, 1, 1);
    }

    return date;
}

From source file:Main.java

/**
 *  Gets the node value as date./*from ww w. j a  v  a2s  .  c om*/
 *
 *@param  node                          Description of the Parameter
 *@return                               The nodeValueAsDate value
 *@exception  DOMException              Description of the Exception
 *@exception  ParseException  Description of the Exception
 */
public final static Date getNodeValueAsDate(Node node) throws DOMException, ParseException {
    if (node == null)
        return null;

    NamedNodeMap attrs = node.getAttributes();
    Node attr = attrs.getNamedItem("DateTimeFormat");

    // Date format
    String format = attr.getNodeValue().trim();
    node = node.getFirstChild();
    if (node != null) {
        String date = node.getNodeValue().trim();
        DateFormat df = new SimpleDateFormat(format);
        return df.parse(date);
    }
    return null;
}

From source file:iqq.im.util.DateUtils.java

public static Date parse(JSONObject jsonobj) throws ParseException, JSONException {
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Date d = format.parse(jsonobj.getInt("year") + "-" + jsonobj.getInt("month") + "-" + jsonobj.getInt("day"));
    return d;//from  w  w w  . ja v a 2s .c o m
}