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 String dateString2dateString(String date, String originFormater, String destFormater) {
    if (date == null || "".equals(date))
        return "";
    SimpleDateFormat formater = new SimpleDateFormat();
    try {//  w  ww.j a  v a2  s  .  co m
        formater.applyPattern(originFormater);
        Date time = formater.parse(date);
        return date2String(destFormater, time);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return "";

}

From source file:Main.java

public static long getQuot(String time1, String time2) {
    long quot = 0;
    SimpleDateFormat ft = new SimpleDateFormat("yyyy/MM/dd");
    try {//  w w  w .j  a va 2s  .c  o  m
        Date date1 = ft.parse(time1);
        Date date2 = ft.parse(time2);
        quot = date1.getTime() - date2.getTime();
        quot = quot / 1000 / 60 / 60 / 24;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return quot;
}

From source file:Main.java

private static boolean isOver(final Date birthday) {
    boolean b = false;
    SimpleDateFormat sdf = new SimpleDateFormat("M-d", Locale.getDefault());
    String md = sdf.format(birthday);
    Date now = new Date();
    sdf = new SimpleDateFormat("yyyy", Locale.getDefault());
    String y = sdf.format(now);/*from  www  . j  a va 2s .c om*/
    String ymd = y + md;
    Date birDate = new Date();
    try {
        birDate = sdf.parse(ymd);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    b = now.getTime() - birDate.getTime() > 0;

    return b;
}

From source file:Main.java

public static Date getDateFromString(String dateString) {

    DateFormat inputFormat = null;

    if (dateString == null) {
        return null;
    }//from w w w.ja  v a  2s .  com

    if (dateString.length() == 19)
        inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
    if (dateString.length() == 10)
        inputFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);

    if (inputFormat == null) {
        return null;
    }

    inputFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date parsed = null;
    try {
        parsed = inputFormat.parse(dateString);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return parsed;
}

From source file:Main.java

public static String getStringByOffset(String strDate, String format, int calendarField, int offset) {
    String mDateTime = null;/*w  ww .  j av a2 s .  c o m*/
    try {
        Calendar c = new GregorianCalendar();
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
        c.setTime(mSimpleDateFormat.parse(strDate));
        c.add(calendarField, offset);
        mDateTime = mSimpleDateFormat.format(c.getTime());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return mDateTime;
}

From source file:Main.java

/**
 *Converts a dateTimeString and makes a Calendar object
 * @param dateTimeString in format 2012-10-15T08:17:00
 * @return Calendar object//www .ja  v a 2 s . c o m
 * */
public static Calendar parseCalendarString(String dateTimeString) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Date date = null;
    try {
        date = dateFormat.parse(dateTimeString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Calendar cal = Calendar.getInstance();
    cal.setTimeZone(TimeZone.getTimeZone("Europe/Stockholm"));
    cal.setTime(date);
    return cal;
}

From source file:Main.java

public static String getConvertDate(String dateStr) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");

    String dateString = dateStr.replace("Z", "GMT+00:00");
    dateFormat.setTimeZone(TimeZone.getDefault());
    Date date = null;/*from  ww w  .j a  v  a  2s . c  om*/
    try {
        date = dateFormat.parse(dateString);
    } catch (java.text.ParseException e1) {
        e1.printStackTrace();
    }

    dateFormat = new SimpleDateFormat("hh:mm a - dd MMM yy");
    String outputText = dateFormat.format(date);

    return outputText;
}

From source file:Main.java

public static String formatDate(String date, int minutes) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date d = null;// w w  w .j  a  va  2 s  . c  om
    try {
        d = sdf.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(d);
    calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - minutes);
    return sdf.format(calendar.getTime());
}

From source file:Main.java

/**
 * <p>/*www .j  av  a  2  s . co m*/
 * <b> public int compare(mDate, dateToCOmpareWith, format) </b>
 * </p>
 *
 * Compares two dates with each other using the rules of the given date
 * format.
 *
 * @param mDate
 *            The date you want to compare
 * @param dateToCompareWith
 *            The date comparing with
 * @param format
 *            An accepted format which must be valid for a
 *            <code>SimpleDateFormat</code>
 * @return <p>
 *         returns 0 if the dates are equal
 *         </p>
 *         <p>
 *         returns > 0 if mDate is larger then the date to compare with
 *         </p>
 *         <p>
 *         returns < 0 if mDate is smaller then the date to compare with
 *         </p>
 */
public static int compareDates(String mDate, String dateToCompareWith, String format) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    Date date1 = null;
    Date date2 = null;
    try {
        date1 = sdf.parse(mDate);
        date2 = sdf.parse(dateToCompareWith);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date1.compareTo(date2);
}

From source file:Utils.java

public static Date parseDate(String date) {
    try {//from  w  w w.jav a 2 s  .c o  m
        return sdf.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return null;
}