Example usage for java.text ParseException printStackTrace

List of usage examples for java.text ParseException printStackTrace

Introduction

In this page you can find the example usage for java.text ParseException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

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;//from  w w w  .j ava2 s.co m
    try {
        date = sdf.parse(dateStr);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return date.getTime();
}

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 {// www.  ja v a 2s .c  om
        date = sd.parse(dateString);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return date;
}

From source file:Main.java

public static Date getDateFromEsmartString(String _esmart) {
    try {//from   w  ww  . j  a v  a 2s . co m
        return mFormat.parse(_esmart);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

/**
 * Get date by year, month/*from   ww  w .  j  a  va  2s  .c  o m*/
 *
 * @param year
 * @param month
 * @return
 */
public static String getDate(int year, int month) {
    String datetime = "" + year + (month > 9 ? month : ("0" + month));
    String parrern = "yyyyMM";
    SimpleDateFormat df = new SimpleDateFormat(parrern);
    try {
        Date date = df.parse(datetime);
        SimpleDateFormat df2 = new SimpleDateFormat(DATE_FORMAT);
        return df2.format(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static Date convertString2Date(String source) {

    if (null == source || source.equals("")) {
        return null;
    }/*from   w  w  w . j  ava2 s  . c om*/

    SimpleDateFormat format = new SimpleDateFormat(DATE_TIME_FORMAT);
    try {
        return format.parse(source);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static String getTime(String user_time) {
    String re_time = null;/*from w w w .j av a 2 s. c om*/
    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);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return re_time;
}

From source file:Main.java

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

    SimpleDateFormat formater = new SimpleDateFormat();
    try {/*from  w w  w  .  j  av  a2s .  c  om*/
        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;
    }
}

From source file:Main.java

public static String formatDate(String date, String format) {
    // "ddd MM, yyyy"

    DateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
    Date parsedDate = new Date();

    try {//w w  w.j  ava 2  s . com
        parsedDate = sdf.parse(date);
        parsedDate.toString();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return "";
}

From source file:Main.java

public static String getConverDateString(String date, String fromFormat, String toFormat) {
    if (TextUtils.isEmpty(date))
        return "";
    SimpleDateFormat sdf = new SimpleDateFormat();
    sdf.applyPattern(fromFormat);/*  ww w .  j av a2  s. c o m*/
    Date d = null;
    try {
        d = sdf.parse(date);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    sdf.applyPattern(toFormat);
    return sdf.format(d);
}

From source file:Main.java

public static Calendar toCalendar(String s, String format) {
    Calendar c = Calendar.getInstance();
    SimpleDateFormat simpleDateFormat;
    simpleDateFormat = new SimpleDateFormat(format, Locale.getDefault());
    s = s.replace("T", " "); // car T est invalide
    try {/*from   w  w  w . java 2  s .c o m*/
        c.setTime(simpleDateFormat.parse(s));
    } catch (ParseException e) {
        //          TODO Auto-generated catch block
        e.printStackTrace();
    }
    return c;
}