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 getChooseDayTime(String date) {
    try {/*from  w w w. j  ava2  s.  com*/
        return (yearFormat.parse(date)).getTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

public static Date createDateTimeFromString(String dt_str, String dt_format) {
    if (dt_str == null || dt_format == null) {
        return null;
    }/* ww  w .  ja v a2  s .co  m*/
    Date dt = null;
    try {
        SimpleDateFormat formatter = new SimpleDateFormat(dt_format);
        dt = formatter.parse(dt_str);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return dt;
}

From source file:Main.java

public static int getDiffHour(String startTime, String endTime) {
    long diff = 0;
    SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {/*from ww  w . j a v  a2  s  . co m*/
        Date startDate = ft.parse(startTime);
        Date endDate = ft.parse(endTime);
        diff = startDate.getTime() - endDate.getTime();
        diff = diff / (1000 * 60 * 60);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return new Long(diff).intValue();
}

From source file:Main.java

public static long getDiff(String startTime, String endTime) {
    long diff = 0;
    SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {//from   w  w w .j av  a2s . c  om
        Date startDate = ft.parse(startTime);
        Date endDate = ft.parse(endTime);
        diff = startDate.getTime() - endDate.getTime();
        diff = diff / 1000;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return diff;
}

From source file:Main.java

public static String getTime(String user_time, String format) {
    String re_time = null;//from w  ww  .j a v a 2  s  .c  o  m
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    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) {
        e.printStackTrace();
    }
    return re_time;
}

From source file:Main.java

public static long changeToTimeStamp(String time) {

    long rand = 0;
    try {//w ww .ja v  a2s .co  m
        Date date1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time + " 00:00:00");

        rand = date1.getTime();
        return rand;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return rand;

}

From source file:Main.java

public static int getYear(String sDate) {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date d = null;/*from  w  w  w  .j  a v a2s .  c  om*/
    try {
        d = df.parse(sDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    if (d == null) {
        return 1971;
    }
    return d.getYear() + 1900;
}

From source file:Main.java

public static String changeStringToDate3(String str) {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.util.Date date6 = null;/*from   www  . j  av a2s  . c  om*/
    try {
        date6 = sdf.parse(str);
        java.sql.Date date7 = new java.sql.Date(date6.getTime());
        Timestamp stamp9 = new Timestamp(date7.getTime());
        return stamp9.toString();
    } catch (ParseException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:Main.java

public static long getStringToDate(String time, String format) {
    if (format != null) {
        sf = new SimpleDateFormat(format);
    } else {//ww  w  .j  av a2s.c om
        sf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    }
    Date date = new Date();
    try {
        date = sf.parse(time);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date.getTime();
}

From source file:Main.java

public static String getTimeStamp(String time) {
    SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.CHINA);
    Date date;//from  w ww  .  j a  v a2 s  . co  m
    String times = null;
    try {
        date = sdr.parse(time);
        long l = date.getTime();
        String stf = String.valueOf(l);
        times = stf.substring(0, 10);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return times;
}