Java Code Examples for java.text.ParseException#printStackTrace()

The following examples show how to use java.text.ParseException#printStackTrace() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * UTC time conversion to local time returns String Date.
 * @param dateToParse
 * @return
 */
public static String parseDate(String dateToParse) {
    try {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        Date dAte = sdf.parse(dateToParse);

        SimpleDateFormat output = new SimpleDateFormat("d MMM yyyy  HH:mm");
        output.setTimeZone(TimeZone.getDefault());

        String formattedTime = output.format(dAte);
        SimpleDateFormat day = new SimpleDateFormat("dd");
        String formattedDay = day.format(dAte) + Helper.getDayOfMonthSuffix(Integer.parseInt(day.format(dAte)));
        formattedTime = formattedTime.replaceFirst(formattedTime.substring(0, formattedTime.indexOf(" ")), formattedDay);
        sdf.parse(dateToParse);
        return formattedTime;
    } catch (ParseException e) {
        e.printStackTrace();
        return dateToParse;
    }
}
 
Example 2
Source Project: cms   File: DateUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static long dateDifferent(String before, String after, String pattern) {
	SimpleDateFormat format = new SimpleDateFormat(pattern);
	try {
		Date dateStart = format.parse(before);
		Date dateStop = format.parse(after);

		long between = (dateStart.getTime() - dateStop.getTime()) / 1000;// 除以1000是为了转换成秒

		return between;
	} catch (ParseException e) {
		e.printStackTrace();
		// throw new Exception("计算时间差失败!");
	}

	return 0;

}
 
Example 3
Source Project: JKCalendar   File: GridCellAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public void onClick(View view) {

        SimpleDateFormat df2 = new SimpleDateFormat("dd-MM-yyy");
        Calendar calendarData = Calendar.getInstance();

        try {
            calendarData.setTime(df2.parse((String) view.getTag()));
        } catch (ParseException e) {
            e.printStackTrace();
        }

//        Calendar calendarData = (Calendar) view.getTag();

        if(iEventDateClick!=null){
            iEventDateClick.onClick(calendarData);
        }

    }
 
Example 4
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
	// Do something with the date chosen by the user
	tv_birthday_info.setText(Integer.toString(year) + "-"
			+ Integer.toString((month + 1)) + "-" + Integer.toString(day));
	String dateString = Integer.toString(year) + "-"
			+ Integer.toString((month + 1)) + "-" + Integer.toString(day)
			+ " " + "12:00:00";

	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	try {
		Date date = sdf.parse(dateString);
		birthday = Long.toString(date.getTime() / 1000);
	} catch (ParseException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example 5
public Transaction(
		String hashId, String timestamp, String author, String comment,
		List<FileInfo> filesAffected) {
	this.hashId = hashId;
	Date dateTemp = null;
	timestamp = timestamp.replace("T", "");
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-ddHH:mm:ssXXX");
	try {
		dateTemp = sdf.parse(timestamp);
	} catch (ParseException e) {
		dateTemp = null;
		e.printStackTrace();
	}
	this.timestamp = dateTemp;
	this.author = author;
	this.comment = comment.toLowerCase();
	this.filesAffected = filesAffected;
}
 
Example 6
Source Project: xmpp   File: TimePopupWindow.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
	String tag = (String) v.getTag();
	if (tag.equals(TAG_CANCEL)) {
		dismiss();
		return;
	} else {
		if (timeSelectListener != null) {
			try {
				Date date = WheelTime.dateFormat.parse(wheelTime.getTime());
				timeSelectListener.onTimeSelect(date);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		dismiss();
		return;
	}
}
 
Example 7
Source Project: kripton   File: DateAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Date toJava(String dataValue) {
	if (dataValue==null) return null;
	Date date=null;
	try {
		date = formatter.parse(dataValue);
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return date;
}
 
Example 8
Source Project: imsdk-android   File: DateUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 将时间字符串转换为Date类型
 * @param dateStr
 * @return Date
 */
public static Date toDate(String dateStr) {
    Date date = null;
    SimpleDateFormat formater = new SimpleDateFormat();
    formater.applyPattern("yyyy-MM-dd");
    try {
        date = formater.parse(dateStr);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date;
}
 
Example 9
public static long jodaTimeToMilliseconds(String dateStr) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
    Date date = null;
    try {
        date = format.parse(dateStr);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date.getTime();
}
 
Example 10
Source Project: kripton   File: DateAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Date toJava(String dataValue) {
	if (dataValue==null) return null;
	Date date=null;
	try {
		date = formatter.parse(dataValue);
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return date;
}
 
Example 11
Source Project: NIM_Android_UIKit   File: TimeUtil.java    License: MIT License 5 votes vote down vote up
public static Date getDateFromFormatString(String formatDate) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    try {
        return sdf.parse(formatDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return null;
}
 
Example 12
Source Project: spring-boot-quartz-demo   File: JobUtil.java    License: MIT License 5 votes vote down vote up
/**
 * Create cron trigger. 
 * 
 * @param triggerName Trigger name.
 * @param startTime Trigger start time.
 * @param cronExpression Cron expression.
 * @param misFireInstruction Misfire instruction (what to do in case of misfire happens).
 *  
 * @return Trigger
 */
protected static Trigger createCronTrigger(String triggerName, Date startTime, String cronExpression, int misFireInstruction){
	PersistableCronTriggerFactoryBean factoryBean = new PersistableCronTriggerFactoryBean();
    factoryBean.setName(triggerName);
    factoryBean.setStartTime(startTime);
    factoryBean.setCronExpression(cronExpression);
    factoryBean.setMisfireInstruction(misFireInstruction);
    try {
        factoryBean.afterPropertiesSet();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return factoryBean.getObject();
}
 
Example 13
Source Project: SuperBoot   File: DateUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 取得当前日期所在周的前一周最后一天
 *
 * @param date
 * @return
 */
public static String getLastDayOfLastWeek(String date) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar calendar = Calendar.getInstance();
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    try {
        calendar.setTime(sdf.parse(date));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return getLastDayOfWeek(calendar.get(Calendar.YEAR),
            calendar.get(Calendar.WEEK_OF_YEAR) - 1);
}
 
Example 14
Source Project: zheshiyigeniubidexiangmu   File: DateUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 字符串到日期
 * @param str_date 只能格式化yyyy-MM-dd
 * @return
 */
public static Date strToDate(String str_date) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = null;
    try {
        date = simpleDateFormat.parse(str_date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return  date;
}
 
Example 15
Source Project: potato-webmvc   File: Helper.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T convert(Class<T> type, Object value) {
	Date date = null;
	DateFormat dateFormat = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");
	try {
		date = dateFormat.parse((String) value);
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return (T) date;
}
 
Example 16
Source Project: mykit-db-sync   File: DateUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static long getLongTypetime(String times) {
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	try {
		return df.parse(times).getTime();
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return 0L;
}
 
Example 17
public static Date parseDateTime(String dateStr){
  	try {
	return dateTimeFormat.parse(dateStr);
} catch (ParseException e) {
	e.printStackTrace();
	return null;
}
  }
 
Example 18
Source Project: jeecg-cloud   File: DateUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 字符串转换成日期
 *
 * @param str
 * @param sdf
 * @return
 */
public static Date str2Date(String str, SimpleDateFormat sdf) {
    if (null == str || "".equals(str)) {
        return null;
    }
    Date date = null;
    try {
        date = sdf.parse(str);
        return date;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 19
Source Project: Viewer   File: ZYDateUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 相同日期不同格式之间转换
 * @param date 当前格式的日期字符串
 * @param originFormater 原格式
 * @param destFormater 目标格式
 * @return 目标格式的日期字符串
 */
public static String dateString2dateString(String date,String originFormater,String destFormater) {
	if (date == null || "".equals(date))
		return "";
	SimpleDateFormat formater = new SimpleDateFormat();
	try {
		formater.applyPattern(originFormater);
		Date time = formater.parse(date);
		return date2String(destFormater, time);
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return "";
	
}
 
Example 20
Source Project: Java   File: ThrowsDemo.java    License: Artistic License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	// show();
	try {
		show2();
	} catch (ParseException e) {
		e.printStackTrace();
	}
}