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 int getMonthFromDate(String origDate) {
    DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
    Date date;//from   www.ja va  2 s . c  o m
    int month = 1;
    try {
        date = formatter.parse(origDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        month = cal.get(Calendar.MONTH);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return month;
}

From source file:Main.java

/**
 * Coverts the specified date/time value to specific milliseconds.
 * // w  w  w  .  j  a v  a2s  .c om
 * @param str to convert into specific date/time.
 * @return converted milliseconds value.
 */
public static long getDateTimeinMilliSeconds(String str) {
    long milliseconds = 0;
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date startdate = null;
    try {
        startdate = formatter.parse(str);
        milliseconds = startdate.getTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return milliseconds;
}

From source file:Main.java

public static int getYearFromDate(String origDate) {
    DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
    Date date;// ww w.jav  a 2s  .  com
    int year = 1;
    try {
        date = formatter.parse(origDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        year = cal.get(Calendar.YEAR);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return year;
}

From source file:Main.java

public static int getDayFromDate(String origDate) {
    DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
    Date date;/*from w  w w.  j  a  v a2  s  . c o m*/
    int day = 1;
    try {
        date = formatter.parse(origDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        day = cal.get(Calendar.DAY_OF_MONTH);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return day;
}

From source file:Main.java

public static String findDateWithFormat(String findDate, String format) {
    findDate = findDate.replace(" ", "").replace("-", "").replace(":", "").replace("/", "").replace(".", "");

    Locale currentLocale = new Locale("KOREAN", "KOREA");
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss", currentLocale);
    SimpleDateFormat returnFormatter = new SimpleDateFormat(format, currentLocale);
    String returnValue = "";
    try {//from w  ww  .j  a v  a  2  s  . co  m
        Date fDate = formatter.parse(findDate);
        returnValue = returnFormatter.format(fDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return returnValue;
}

From source file:Main.java

/**
 * Parses XML datetime object to Date object
 *
 * @param xmlDateTime XML Datetime as a String
 * @return Datetime object/* w  w w. ja  va  2s .com*/
 * @throws ParseException if Parsing exception occurred
 */
public static Date parseXmlDateTime(String xmlDateTime) {
    Date parsedDate = new Date();
    try {
        xmlDateTime = xmlDateTime.replace("Z", "+0000");
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.getDefault());
        parsedDate = dateFormat.parse(xmlDateTime);
        return parsedDate;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return parsedDate;
}

From source file:Main.java

public static String getTweleveHourTimeWith2DigtYear(String timeToConvert) {
    String convertedTime = "";
    if (timeToConvert == null)
        return null;

    try {//from w ww. ja v a  2s  .c o  m
        final Date dateObj = serverSideDateFormator.parse(timeToConvert);
        convertedTime = new SimpleDateFormat("K:mm a MM/dd/yy").format(dateObj);
    } catch (final ParseException e) {
        e.printStackTrace();
    }
    return convertedTime;
}

From source file:Main.java

public static String getTweleveHourTime(String timeToConvert) {
    String convertedTime = "";
    if (timeToConvert == null)
        return null;

    try {//w w w. j av a  2 s  . c om
        final Date dateObj = serverSideDateFormator.parse(timeToConvert);
        convertedTime = new SimpleDateFormat("K:mm a MM/dd/yyyy").format(dateObj);
    } catch (final ParseException e) {
        e.printStackTrace();
    }
    return convertedTime;
}

From source file:Main.java

public static final JFormattedTextField createMaskFormattedTextField(String format) {
    try {/*from   w  w  w.ja v  a 2s .com*/
        MaskFormatter mf = new MaskFormatter(format);
        JFormattedTextField field = new JFormattedTextField(mf);
        return field;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Date stringToDate(String mFirstDate, SimpleDateFormat yearformat) {

    Date parse = null;/*from   w  w w . j a  v  a  2s.  c o m*/
    try {
        if (mFirstDate != null) {
            parse = yearformat.parse(mFirstDate);
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return parse;
}