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 formatTime(String time) {
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    Date date;// ww w .  jav  a2s.  c om
    try {
        date = sdf.parse(time);
        long millis = date.getTime();
        return millis;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

/**
 * Converts a string representation of a date to that date
 *
 * @param dateString The string to parse
 * @param format     The format to parse the string with
 * @return The date, or null// w w  w.j av a  2 s . c  om
 */
public static Date stringToDate(String dateString, String format) {
    if (dateString == null) {
        return null;
    }
    SimpleDateFormat df = new SimpleDateFormat(format, Locale.US);
    try {
        return df.parse(dateString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String getRelativeTimeAgo(String rawJsonDate) {
    String twitterFormat = "EEE MMM dd HH:mm:ss ZZZZZ yyyy";
    SimpleDateFormat sf = new SimpleDateFormat(twitterFormat, Locale.ENGLISH);
    sf.setLenient(true);//from   w w  w  .  j  a v  a 2 s . c o m

    String relativeDate = "";
    try {
        long dateMillis = sf.parse(rawJsonDate).getTime();
        relativeDate = DateUtils
                .getRelativeTimeSpanString(dateMillis, System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS)
                .toString();
    } catch (ParseException e) {
        e.printStackTrace();
    }

    // Shorten relative date
    relativeDate = relativeDate.replaceAll(" ", "").replace("seconds", "s").replace("second", "s")
            .replace("minutes", "m").replace("minute", "m").replace("hours", "h").replace("hour", "h")
            .replace("days", "d").replace("day", "d").replace("weeks", "w").replace("week", "w")
            .replace("months", "M").replace("month", "M").replace("years", "y").replace("year", "y")
            .replace("ago", "").replace("in", "").replace("0s", "just now");

    return relativeDate;
}

From source file:Main.java

public static boolean isOutCurrentTime(String endTime, String format) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
    try {//from   w  ww  . java 2 s  . com
        Date endDate = simpleDateFormat.parse(endTime);
        long endTimeLong = endDate.getTime();

        Date currDate = new Date(System.currentTimeMillis());
        String currTime = simpleDateFormat.format(currDate);
        currDate = simpleDateFormat.parse(currTime);
        long currentTime = currDate.getTime();

        return currentTime > endTimeLong;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

public static String getJobDateFormat(String strDate, String inputFormat) {
    String formatDate = "";
    String dayFormat[] = strDate.split("-");
    int day = Integer.parseInt(dayFormat[0]);
    try {/*  w w w  .java 2s .  c  o m*/
        String dayNumberSuffix = getDayNumberSuffix(day);
        SimpleDateFormat inputDateFormat = new SimpleDateFormat(inputFormat, Locale.US);
        Date date = inputDateFormat.parse(strDate);
        SimpleDateFormat outputDateFormat = new SimpleDateFormat(" d'" + dayNumberSuffix + "' MMMM yyyy",
                Locale.US);
        formatDate = outputDateFormat.format(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return formatDate;
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
static String futureDate() {
    // take current date and increment
    Calendar cal = Calendar.getInstance(TimeZone.getDefault());
    Date currentLocalTime = cal.getTime();
    SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
    date.setTimeZone(TimeZone.getDefault());
    _currentDate = date.format(currentLocalTime);
    try {/*  w  ww  . j a v a  2s .c  o m*/
        cal.setTime(date.parse(_currentDate));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    cal.add(Calendar.DATE, 30);
    _currentDate = date.format(cal.getTime());
    return _currentDate;
}

From source file:Main.java

public static String getLocalTimeString(String strGMTTime) {
    String strLocalTime = null;/*from   w ww  . ja v  a2s .com*/
    try {
        GMTTimeFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
        Date date = GMTTimeFormatter.parse(strGMTTime);
        LocalTimeFormatter.setTimeZone(TimeZone.getDefault());
        strLocalTime = LocalTimeFormatter.format(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return strLocalTime;
}

From source file:Main.java

public static boolean isCurrentTimeInBetween(String startTime, String endTime, String format) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
    try {/*from  w  w  w  .j  av a 2s  . com*/
        Date startDate = simpleDateFormat.parse(startTime);
        long startTimeLong = startDate.getTime();

        Date endDate = simpleDateFormat.parse(endTime);
        long endTimeLong = endDate.getTime();

        Date currDate = new Date(System.currentTimeMillis());
        String currTime = simpleDateFormat.format(currDate);
        currDate = simpleDateFormat.parse(currTime);
        long currentTime = currDate.getTime();
        return currentTime >= startTimeLong && currentTime < endTimeLong;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

public static long string2Millis(String time, String pattern) {
    try {/* w w  w.ja  v a2 s .c om*/
        return new SimpleDateFormat(pattern, Locale.getDefault()).parse(time).getTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return -1;
}

From source file:Main.java

/**
 * Get week by datetime, datetime format must be contracted with DATE_FORMAT.
 *
 * @param datetime/*from  ww  w. j av a2 s. c om*/
 * @return
 */
public static String getWeek(String datetime) {
    Calendar cal = Calendar.getInstance();
    DateFormat f = new SimpleDateFormat(DATE_FORMAT);
    try {
        cal.setTime(f.parse(datetime));
        int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (week_index < 0) {
            week_index = 0;
        }
        return WEEKS[week_index];
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return "";
}