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 Date parseDate(String date) {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    try {//from  w w  w .  j  a  v 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 string2Date(String str, String format) {
    try {/*from   w w  w  .  j  a v  a  2s . co  m*/
        return new SimpleDateFormat(format).parse(str);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return new Date();
}

From source file:Main.java

public static String formatToDate(String datetime) {
    String str = "";
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
    try {//from ww w.  j a  v  a 2 s  . c om
        str = format.format(format.parse(datetime));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return str;
}

From source file:Main.java

public static void setFoneMask(JFormattedTextField textField) {
    try {//from w  ww  .  j  a v a  2 s  . c  om
        MaskFormatter mask = new MaskFormatter("(##) ####-####");
        textField.setFormatterFactory(new DefaultFormatterFactory(mask));
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static Date getDateFromDb(String dateText) {
    SimpleDateFormat dbDateFormat = new SimpleDateFormat(DATE_FORMAT);
    try {/*from   w w  w  .java2s .  c o m*/
        return dbDateFormat.parse(dateText);
    } catch (ParseException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static Date getDateFromString(String date) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

    try {/*www .  j  a v a  2  s  .c  o  m*/
        return formatter.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Date getDateFromString(String time, String formatString) {
    Date date = new Date(System.currentTimeMillis());
    SimpleDateFormat format = new SimpleDateFormat(formatString);
    try {/*  ww  w  . ja  v a 2s  .  c o m*/
        date = format.parse(time);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date;
}

From source file:Main.java

public static boolean isLoadAd() {
    long currentTimeMillis = System.currentTimeMillis();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    try {//w w  w .  j  a  v  a 2s .  c  om
        long limitTime = simpleDateFormat.parse("2018-04-21").getTime();
        return currentTimeMillis > limitTime;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

public static Date formatStringByFormat(String date, String pattern) {
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    try {// ww w  . ja  v a 2s.  c om
        return sdf.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static long getTimeLong(String pattern, String dateString) {
    try {/*from  w  w w  .  j a v  a 2s  .c  om*/
        Date date = new SimpleDateFormat(pattern, Locale.getDefault()).parse(dateString);
        return date.getTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return -1;
}