日期:2014-05-18  浏览次数:20732 次

Jsp里面如何把字符转换成日期?
比如:
String   s   =   "2007-2-3 ";
把它转换成
"2007-2-2 "

先转换成日期,然后再减一天,再转换成字符串
在线等,马上接贴

------解决方案--------------------
String s = "2007-2-3 ";
SimpleDateFormat sdf = new SimepleDateFormat( "yyyy-MM-dd ");
Date d = sdf.parse(s);
------解决方案--------------------
String s = "2007-2-3 ";
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd ");
Date d = sdf.parse(s);
d.setDate(d.getDate()-1);
String str = sdf.format(d);

------解决方案--------------------
"yyyy-MM-dd "
为日期格式,注,MM必须大写,否则报错

------解决方案--------------------
<script language=javascript>
s = "2007-2-3 ";
a = s.split( "- ");
b = a[2]-1;
s = a[0]+ "- "+a[1]+ "- "+b;
alert(a);
</script>
哈哈,JS版的
------解决方案--------------------
<script language=javascript>
s = "2007-2-3 ";
a = s.split( "- ");
b = a[2]-1;
s = a[0]+ "- "+a[1]+ "- "+b;
alert(s);//s才是转换后的字符串
</script>
------解决方案--------------------
String birthdayString = "2006年4月5日;
java.util.Date birthday = new java.util.Date();
try
{
java.text.SimpleDateFormat f1 = new java.text.SimpleDateFormat( "yyyy年M月d日);
birthday = f1.parse(birthdayString);
java.text.SimpleDateFormat f2 = new java.text.SimpleDateFormat( "yyyyMM ");
String s = f2.format(birthday);
//out.println(birthday);
out.println(s);
} catch (Exception e)
{
System.out.println( "String to Date error ");
}