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 isDateAfter(String curdate, String dob) {
    try {/*w w w.  j  ava 2 s.  c  om*/
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        Date date1 = df.parse(curdate);
        Date startingDate = df.parse(dob);

        if (startingDate.after(date1))

            return true;
        else
            return false;
    } catch (Exception e) {

        return false;
    }
}

From source file:Main.java

public static Date stringMM_dd_yyyyToDate(String aStrDate) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
    try {/*from ww  w .j  a  v  a2  s.co  m*/
        return dateFormat.parse(aStrDate);
    } catch (java.text.ParseException ex) {
        return null;
    }
}

From source file:Main.java

public static Calendar dateUSToCalendar(String data) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
    Date date = sdf.parse(data);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from  www .j  a va  2s  . c  o  m
    return calendar;
}

From source file:Main.java

public static Date dateJSONStringToDateOcupacioAules(String sDate) {
    Date date = null;/*  ww  w.jav  a2  s  .  co m*/
    try {
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        date = formatter.parse(sDate);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return date;
}

From source file:Main.java

public static Calendar getStringDateToCal(String date) {
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    try {//from w w  w . j  a v a2s .c  om
        cal.setTime(sdf.parse(date));
    } catch (Exception e) {

    }
    return cal;
}

From source file:Main.java

public static Date toDate(String template) {
    Date date = null;// w  w w.j  a  va 2 s. co m
    try {
        SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        date = inFormat.parse(template);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return date;
}

From source file:Main.java

public static Date convertStringToDate(String strDate, String format) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
    try {/*from  w  ww  .  j av  a2 s. co m*/
        return simpleDateFormat.parse(strDate);
    } catch (ParseException e) {
        return null;
    }
}

From source file:Main.java

public static String formatDateTime(String yyyyMMddhhmmss) {
    try {//from   w ww . j a  va 2 s.  c o  m
        SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = format1.parse(yyyyMMddhhmmss.replace(" ", ""));

        SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format2.format(date);
    } catch (Exception e) {
        e.printStackTrace();
        return yyyyMMddhhmmss;
    }
}

From source file:Main.java

public static long getTime(String time, String pattern) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
    try {// w  w  w  .j a va  2  s .  com
        return simpleDateFormat.parse(time).getTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

public static String formatTime(String time, String pattern) {
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    try {//w w w.  jav  a 2  s  . c o m
        Date date = format.parse(time);
        return format.format(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return "";
}