如何将String date=“2008-01-01”
转换为时间类型,因为我数据库中的字段是DateTime类型的
转换为时间类型,因为我数据库中的字段是DateTime类型的
解决方案 »
- proxool连接池的问题 大家帮帮忙~急!
- 如何获得工程下某文件夹的所有文件名LIST?
- 如何在Tomcat中设置只能通过URL访问,而不能通过IP访问?
- apache 处理图片盗链问题
- 问题:include指令和include动作!
- 关于Hibernate与HTTPSession的问题
- 探讨Tiles框架和dTree菜单组件的协调问题!!嫌100分不够?再开贴送分
- 在线求救!一个处理空值的问题!!!
- org.apache.commons.dbcp.BasicDataSourceFactory类哪儿有?
- 我用servlet 时出现这个问题~~~很奇怪!
- JSP中的下载问题
- 急问这种情况采用文件流输出下载如何解决
private static final String FORMAT_2 = "yyyy-MM-dd HH:ss"; //24小时至
private static final String FORMAT_1 = "yyyy-MM-dd hh:ss"; //12小时至....................................
date = formatDate(date, FORMAT_1, FORMAT_2);private static String formatDate(String inputDate, String inputDateFormat, String outputDateFormat) throws Exception {
if (CL0Util.isNullString(inputDate)) {
return CL0Util.getSpace(0);
}
return formatDate(getDate(inputDate, inputDateFormat), outputDateFormat);
}public static String formatDate(Date inputDate, String outputFormat) {
if (null == inputDate) {
return null;
} if (null == outputFormat) {
throw new NullPointerException("The output format is null.");
} try {
SimpleDateFormat sdf = new SimpleDateFormat(outputFormat); return sdf.format(inputDate);
} catch (Exception ex) {
throw new IllegalArgumentException("The output format is invalid.");
}
}public static Date getDate(String inputDateTime, String inputFormat) {
if (null == inputDateTime) {
return null;
} if (null == inputFormat) {
throw new NullPointerException("The input format is null.");
}
try {
SimpleDateFormat sdf = new SimpleDateFormat(inputFormat);
return sdf.parse(inputDateTime);
} catch (Exception ex) {
throw new IllegalArgumentException("The input format is invalid.");
}
}
或者你自己转换成java.sql.Date再使用setDate....需要时间的话需要Timestamp
String begin="2008-03-10";
java.text.SimpleDateFormat localTime = new java.text.SimpleDateFormat("yyyy-MM-dd");
Date newbegin = localTime.parse(begin);