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:edu.utah.further.core.util.jaxb.JaxbConversionUtil.java

/**
 * @param s//from ww w . j  ava 2s . c o m
 * @param dateFormat
 * @return
 */
public static XMLGregorianCalendar parseDateGregorian(final String s, final SimpleDateFormat dateFormat) {
    try {
        final Date date = dateFormat.parse(s);
        final GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        return DATATYPE_FACTORY.newXMLGregorianCalendar(calendar);
    } catch (final ParseException e) {
        throw new ApplicationException("Bad date field " + s, e);
    }
}

From source file:com.fluke.util.Util.java

public static Date getDate(String date) throws ParseException {
    SimpleDateFormat formatter = new SimpleDateFormat(format);
    return formatter.parse(date);
}

From source file:com.castis.xylophone.adsmadapter.common.util.CiDateUtil.java

public static Date convertDate(String srcDateString, String format) {
    Date tmpDate = new Date();
    SimpleDateFormat simple = new SimpleDateFormat(format);
    try {/* ww w  . j  a v  a2 s.  c  om*/
        tmpDate = simple.parse(srcDateString);
    } catch (ParseException e) {
        log.warn("Parse Exception : src-" + srcDateString + ", format-" + format);
        return null;
    }
    return tmpDate;
}

From source file:net.duckling.ddl.web.agent.util.AuthUtil.java

public static String getAuthEmail(String auth) {
    try {//from w ww.  j a  va  2s . co  m
        String decode = decodeAuth(auth);
        JSONObject obj = new JSONObject(decode);
        String email = obj.getString("email");
        String date = obj.getString("date");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d = sdf.parse(date);
        if (notExpired(d)) {
            return email;
        }
    } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException
            | BadPaddingException | UnsupportedEncodingException e) {
        return null;
    } catch (ParseException e) {
        return null;
    }
    return null;
}

From source file:Main.java

public static long stringDateToLong(String dateStr) {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
    Date date = null;/*w  w w.  ja  v  a  2s . c  om*/
    try {
        date = sdf.parse(dateStr);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return date.getTime();
}

From source file:com.castis.xylophone.adsmadapter.common.util.CiDateUtil.java

public static Calendar convertCalendar(String srcDateString, String format) {
    Date tmpDate = new Date();
    SimpleDateFormat simple = new SimpleDateFormat(format);
    try {//  ww  w  . ja v a  2 s.  co  m
        tmpDate = simple.parse(srcDateString);
    } catch (ParseException e) {
        log.warn("Parse Exception : src-" + srcDateString + ", format-" + format);
        return null;
    }
    Calendar cal = Calendar.getInstance();
    cal.setTime(tmpDate);

    return cal;
}

From source file:Main.java

public static Date getDateFromString(String inputString) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = null;/*from  w  w  w  . java2  s.  c  o m*/
    try {
        date = sdf.parse(inputString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date;
}

From source file:Main.java

public static String getTime(String user_time) {
    String re_time = null;//  w w w .j  ava2s .com
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date d;
    try {

        d = sdf.parse(user_time);
        long l = d.getTime();

        String str = String.valueOf(l);
        // re_time = str.substring(0, 10);
        re_time = str;

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return re_time;
}

From source file:Main.java

public static Date toDateFromString(String dateString) {
    // 1985-04-12T23:20:50.52Z
    SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
    // sd.setTimeZone(TimeZone.getDefault());
    Date date = new Date();
    try {//from   w  ww .ja  v  a  2 s  .co m
        date = sd.parse(dateString);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return date;
}

From source file:Main.java

public static String calculateByDate(String date, String format, int dayOffset) {

    SimpleDateFormat formater = new SimpleDateFormat();
    try {/*from   w ww  .  ja  va2s  .c  o  m*/
        formater.applyPattern(format);
        Date time = formater.parse(date);
        long ts = time.getTime() + dayOffset * 24 * 3600 * 1000L;
        Date newDate = new Date(ts);
        return date2String(format, newDate);
    } catch (ParseException e) {
        e.printStackTrace();
        return null;
    }
}