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 getUTCTimeFromLocal(String localTime) {
    java.util.Date UTCDate = null;
    String localTimeStr = null;//w w  w .j a va 2s  .  c om
    SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault());
    try {
        UTCDate = format.parse(localTime);
        localTimeStr = format.format(UTCDate.getTime() - TimeZone.getDefault().getRawOffset());
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return localTimeStr;
}

From source file:Main.java

public static Calendar StringToCalendar(String datetime) {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    try {//w  ww.  j av a 2  s  . com
        calendar.setTime(simpleDateFormat.parse(datetime));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return calendar;
}

From source file:Main.java

public static String getLocalTimeFromUTC(String UTCTime) {
    java.util.Date UTCDate = null;
    String localTimeStr = null;/*from   w  ww .  j a va  2s. c  o  m*/
    SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault());
    try {
        UTCDate = format.parse(UTCTime);
        localTimeStr = format.format(UTCDate.getTime() + TimeZone.getDefault().getRawOffset());
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return localTimeStr;
}

From source file:Main.java

public static GregorianCalendar getCalFromString(String data) {
    dateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.ITALIAN);
    try {/*from w  ww . ja va  2  s.c  o  m*/
        Date dateTime = dateFormat.parse(data);
        GregorianCalendar gregCalendar = new GregorianCalendar();
        gregCalendar.setTime(dateTime);
        return gregCalendar;
    } catch (ParseException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static String getSpecifiedDayAfter(String specifiedDay) {
    Calendar c = Calendar.getInstance();
    Date date = null;/*  ww w .j  av a 2s  .c o  m*/
    try {
        date = new SimpleDateFormat("yyyy-MM-dd").parse(specifiedDay);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    c.setTime(date);
    int day = c.get(Calendar.DATE);
    c.set(Calendar.DATE, day + 1);
    String dayAfter = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
    return dayAfter;
}

From source file:Main.java

public static String getSpecifiedDayBefore(String specifiedDay) {
    Calendar c = Calendar.getInstance();
    Date date = null;//from  ww w  .ja v a2  s.co  m
    try {
        date = new SimpleDateFormat("yyyy-MM-dd").parse(specifiedDay);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    c.setTime(date);
    int day = c.get(Calendar.DATE);
    c.set(Calendar.DATE, day - 1);
    String dayBefore = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
    return dayBefore;
}

From source file:Main.java

public static Date convertStringDateToDate(String date) {
    try {/*from  ww  w.java  2 s .com*/
        if (date != null && date.compareTo("null") != 0 && date.compareTo("") != 0) {
            if (date.length() > 11) {
                return (Date) new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.getDefault()).parse(date);
            } else {
                return (Date) new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).parse(date);
            }
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String convertToReadableFormat(String input, String format) {
    try {/*from   ww  w .  j a v  a  2 s.c  o  m*/
        SimpleDateFormat df = new SimpleDateFormat(format);
        Date date = df.parse(input);

        df = new SimpleDateFormat("hh:mm a");
        String readableDate = df.format(date);
        return readableDate;
    } catch (ParseException p) {
        p.printStackTrace();
    }

    return input;

}

From source file:Main.java

public static Date getSpritDate(String str) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy/M/d");
    Date date = null;/*from   w  w  w  .j  ava2 s .  c  o m*/

    try {
        date = format.parse(str);
        date.setMinutes(0);
        date.setHours(0);
        date.setSeconds(0);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return date;
}

From source file:Main.java

public static long parseFeedDate(String date) {
    SimpleDateFormat formatter;//from   w w w .j  a  v  a  2s  .  c  o m
    if (date.contains(" - ")) {
        date = date.split(" - ")[0].trim();
    }
    formatter = new SimpleDateFormat("d. MMMM yyyy");

    Date d = null;
    try {
        d = formatter.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return d.getTime();
}