小问题————在线急等

lijianlin 2005-11-09 10:43:19
请问jsp下如何将字符串类型转换成日期型,请给写个简单例子
...全文
84 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lijianlin 2005-11-09
  • 打赏
  • 举报
回复
楼上的,我知道在java下它没有问题,但是在jsp下总是提示The type Date is ambiguous
bixuehui 2005-11-09
  • 打赏
  • 举报
回复
private static Date stringToTimestamp(String bYmd) throws Exception {
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;
}
没有问题的我测试都通过了。
lijianlin 2005-11-09
  • 打赏
  • 举报
回复
为什么总是提示
The type Date is ambiguous

bixuehui 2005-11-09
  • 打赏
  • 举报
回复
/**
*
* @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;
}
liangkandy2002 2005-11-09
  • 打赏
  • 举报
回复
<%
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());
%>
classjava 2005-11-09
  • 打赏
  • 举报
回复
<% SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
Date date=format.parse("2005-10-20");
System.out.println(date);

%>
bixuehui 2005-11-09
  • 打赏
  • 举报
回复
jsp和java下都应该没有问题的,你可以把它写成bean来用,把参数传给它不就可以了吗?
要不你把你的代码贴出来看看.

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧