请问jsp下如何将字符串类型转换成日期型,请给写个简单例子
解决方案 »
- JSP 做网站,选个合适的框架
- 关于搜索引擎优化问题:JSP转换为静态页面?谁会,详细教我....
- struts logic:iterate 的应用 谢谢大家进来看看
- 急求数据库日期查询问题~~!!!!!!!!!!!!在线等~~~~~~~~~~~
- 用apache的fileupload上传文件失败,各位大虾帮忙解决哈!先谢谢了!
- 可以这样http://219.245.122.84:8080/访问吗
- 大家帮我看看我的插入和删除语句哪里错了啊,怎么看不到结果呢,查询都可以的
- [求教] JSP大量用户数据上报系统的性能考虑
- 怎么配置tomcat服务器?
- 求sql分页的例子
- 求助,常用jsp开发工具都有哪些????
- 求SMS解决方案
Date date=format.parse("2005-10-20");
System.out.println(date);%>
String values = "2005-02-25";
int year = Integer.parseInt(values.substring(0,4));
int month = Integer.parseInt(values.substring(5,7));
int day = Integer.parseInt(values.substring(8,10));
Date value = new Date(year,month,day);
out.println(value.getYear());
out.println(value.getMonth());
out.println(value.getDate());
%>
*
* @param bYmd
* String
* @return Date
* @throws Exception
* ex
*/
private Date stringToTimestamp(String bYmd) throws Exception {
Date d = null;
try {
if (bYmd == null || bYmd.trim().length() == 0) {
return t;
} else {
if (bYmd.length() == 8) {
bYmd = bYmd.substring(0, 4) + "-" + bYmd.substring(4, 6)
+ "-" + bYmd.substring(6)
}
bYmd = bYmd.replace('/', '-');
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-mm-dd");
d = sdf.parse(bYmd);
}
} catch (Exception e) {
throw e;
}
return d;
}
The type Date is ambiguous
Date d = null;
try {
if (bYmd == null || bYmd.trim().length() == 0) {
return d;
} else {
if (bYmd.length() == 8) {
bYmd = bYmd.substring(0, 4) + "-" + bYmd.substring(4, 6)
+ "-" + bYmd.substring(6);
}
bYmd = bYmd.replace('/', '-');
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-mm-dd");
d = sdf.parse(bYmd);
}
} catch (Exception e) {
throw e;
}
return d;
}
没有问题的我测试都通过了。
要不你把你的代码贴出来看看.