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 tryParseDate(String dateStr, Date defaultValue) {
    if (dateStr == null) {
        return defaultValue;
    }/*from  w  w w. jav a  2 s . c om*/
    DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = defaultValue;
    try {
        date = dateformat.parse(dateStr);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date;
}

From source file:Main.java

public static Date getDateForString(String dateString) {

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

    Date date = null;//from  w  w  w.  j av  a2 s.  co  m
    try {
        date = dateFormat.parse(dateString);

    } catch (ParseException e) {
        e.printStackTrace();
    }

    return date;

}

From source file:Main.java

/**
 * Parse the date from server to String for local database
 *
 * @param date_received date received from server
 * @return Date for storing in local database
 *///from  ww w. j a va  2 s  .  c  o  m
public static Date parseDateFromString(String date_received) {
    //2014-06-28 14:56:59
    SimpleDateFormat dateFormat_received = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss", Locale.getDefault());
    Date date = null;
    try {
        date = dateFormat_received.parse(date_received);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date;
}

From source file:Main.java

public static String getUTCDateTimeFromLocalDateTime(String localTimeStr) {
    java.util.Date nowDate = null;
    String UTCDate = null;//from ww w .  ja  va  2 s  .co  m
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
    try {
        nowDate = format.parse(localTimeStr);
        UTCDate = format.format(nowDate.getTime() - TimeZone.getDefault().getRawOffset());
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return UTCDate;

}

From source file:Main.java

public static String getLocalDateTimeFromUTCDateTime(String UTCDateTime) {
    java.util.Date nowDate = null;
    String UTCDate = null;/*from w w w.ja v  a 2  s .co  m*/
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
    try {
        nowDate = format.parse(UTCDateTime);
        UTCDate = format.format(nowDate.getTime() + TimeZone.getDefault().getRawOffset());
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return UTCDate;

}

From source file:Main.java

public static String getCurrentAgeByBirthdate(String brithday) {

    SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
    java.util.Date date = new Date();
    java.util.Date mydate = null;
    try {//ww  w. j  a  v a2  s .c o  m
        mydate = myFormatter.parse(brithday);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000) + 1;

    String year = new java.text.DecimalFormat("#").format(day / 365f);

    return year;
}

From source file:Main.java

public static String getDateForMouth(String dateString) {

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
    SimpleDateFormat simpledateformat = new SimpleDateFormat("MM-dd");
    String s = "";
    Date newDate = null;//  w  w  w.j av a2  s  .co  m
    try {
        newDate = dateFormat.parse(dateString);
        s = simpledateformat.format(newDate);
    } catch (ParseException e) {
        e.printStackTrace();
        s = "";
    }
    return s;
}

From source file:Main.java

public static final void setMaskFormatter(JFormattedTextField textField, String format) {
    try {//from   w  w  w .ja  va 2  s  . co  m
        MaskFormatter mf = new MaskFormatter(format);
        textField.setFormatterFactory(new DefaultFormatterFactory(mf));
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static Calendar StringToCal(String date) {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm", Locale.KOREA);
    Date scheduleTime = null;//from w ww  .jav a  2 s . c  om
    try {
        scheduleTime = sdf.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    Calendar cal = Calendar.getInstance();
    cal.setTime(scheduleTime);

    return cal;

}

From source file:Main.java

public static String getNowTime(int i) {
    SimpleDateFormat dft = new SimpleDateFormat("yyyyMMdd");
    Date beginDate = new Date();
    Calendar date = Calendar.getInstance();
    date.setTime(beginDate);/*from   ww  w.  j  a va2s .c  o  m*/
    date.set(Calendar.DATE, date.get(Calendar.DATE) - i);
    Date endDate = null;
    try {
        endDate = dft.parse(dft.format(date.getTime()));
        String format = dft.format(endDate);
        return format;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return "";
}