Example usage for java.text SimpleDateFormat parse

List of usage examples for java.text SimpleDateFormat parse

Introduction

In this page you can find the example usage for java.text SimpleDateFormat 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 boolean isValidDate(String inDate) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setLenient(false);/*from   w  w  w  . j  a  v  a 2s .c o  m*/
    try {
        dateFormat.parse(inDate.trim());
    } catch (ParseException pe) {
        return false;
    }
    return true;
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
public static Date getDateFromString(String dateString) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.S'Z'");
    return sdf.parse(dateString);
}

From source file:Main.java

public static Date string2date(String date, String format) {
    try {//from   w w w  . java 2s  . c  o  m
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Date result = sdf.parse(date);
        sdf = null;
        return result;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

}

From source file:Main.java

/**
 * ???long?????/*from   w  w  w .  j av  a 2 s  .  co m*/
 * 
 * @param s
 * @return
 */
public static long getDateLong(String s) {
    long l = 0;
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        l = sdf.parse(s).getTime();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return l;
}

From source file:Main.java

public static Date parseDate(String date) {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    try {// www  . j av a 2  s.c o  m
        return df.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
        return new Date();
    }
}

From source file:Main.java

public static Date getDateFromString(String dateStr, String pattern) {
    Date date = null;//from   w  ww .ja va 2  s  .  c  o  m
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);

    try {
        date = sdf.parse(dateStr);
    } catch (Exception e) {

    }
    return date;
}

From source file:Main.java

public static long dateStrToLong(String pattern, String strDate) {
    long date = 0;
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    try {/*w w w  . java2s  . co  m*/
        Date t = sdf.parse(strDate);
        date = t.getTime();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return date;
}

From source file:Main.java

public static long getTimeInMills(String dateStr) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
    Date date = sdf.parse(dateStr);
    return date.getTime();
}

From source file:Main.java

public static long getMs(String str, String format) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    try {//from   w ww.ja va 2 s.  co  m
        Date date = sdf.parse(str);
        return date.getTime();
    } catch (ParseException e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

public static Date parseDate(String date, String datePartten) throws ParseException {
    SimpleDateFormat df = new SimpleDateFormat(datePartten);
    Date d = df.parse(date);
    return d;/*from  ww  w  . ja va 2s.  co m*/
}