对于一个String进行SimpleDateFormat转换的,
这个String一共8位
前六位是yyyyww,最后两位是固定的"00"所以想生成了一个SimpleDateFormat("yyyyww'00'")来parse这个String的。可惜不能转换的,扔出了一个Unparseable date的ParseException。各位帮我看看是什么问题的?
如果要解决的话要怎么来写这个FormatDe,谢谢的。
因为这个String不能修改的,只能8位一起解析的。OS:WindowsXp Pro JRE:1.5.0_11, 1.4.2_13程序和结果如下的:import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;public class fTest2 { /**
* @param args
*/
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception{
Calendar today = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyww'00'");
try {
today.setTime(dateFormat.parse("20072600"));
} catch (ParseException ex) {
System.out.println(ex.getMessage());
}
System.out.println(dateFormat.format(today.getTime()));
}
}Console:
Unparseable date: "20072600"
20072600
这个String一共8位
前六位是yyyyww,最后两位是固定的"00"所以想生成了一个SimpleDateFormat("yyyyww'00'")来parse这个String的。可惜不能转换的,扔出了一个Unparseable date的ParseException。各位帮我看看是什么问题的?
如果要解决的话要怎么来写这个FormatDe,谢谢的。
因为这个String不能修改的,只能8位一起解析的。OS:WindowsXp Pro JRE:1.5.0_11, 1.4.2_13程序和结果如下的:import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;public class fTest2 { /**
* @param args
*/
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception{
Calendar today = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyww'00'");
try {
today.setTime(dateFormat.parse("20072600"));
} catch (ParseException ex) {
System.out.println(ex.getMessage());
}
System.out.println(dateFormat.format(today.getTime()));
}
}Console:
Unparseable date: "20072600"
20072600
Unparseable date: "20072600"
20072600javadoc里面说无关文字用单引号括起来的,所以加了''试试的
try {
today.setTime(dateFormat.parse("20072600"));
} catch (ParseException ex) {
System.out.println(ex.getMessage());
}
会把20072600解析成 2056/10/22的,呵呵,不知道jre怎么搞出来的。想要解析成 2007/06/24的
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyww");
try {
today.setTime(dateFormat.parse("20072600".substring(0,6)));
} catch (ParseException ex) {
System.out.println(ex.getMessage());
}
会把20072600解析成 2056/10/22的,呵呵,不知道jre怎么搞出来的。
----------------------------------------------------------------
2007年的第 2600 个星期
用了yyyywwSS的话,就是最后两位只要是秒数的话就可以通过了的,所以和我想要的东西都一点差别的。还是要谢谢以上给我回答的朋友的,我本来不怎么来csdn的,今天碰到问题了的以后,才跑到这里来求助的,没有想到给了这么多回复的。
以后也要多到这里逛逛的。