本帖最后由 smile_joe 于 2013-4-20 19:20 编辑
- import java.text.DateFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- public class Test2 {
- /**
- * @param args
- * @throws ParseException
- */
- public static void main(String[] args) {
- method();
- }
- public static void method() {
- String s1 = "2010-10-10";
- String s2 = "2013/5/6";
- DateFormat df=new SimpleDateFormat();
- Date d1 = null;
- try {
- d1 = df.parse(s1);
- System.out.println(d1);
- } catch (ParseException e) {
- // TODO Auto-generated catch block
-
- }
- Date d2 = null;
- try {
- d2 = df.parse(s2);
- System.out.println(d2);
- } catch (ParseException e) {
- // TODO Auto-generated catch block
-
- }
- long l1=d1.getTime();
- long l2=d2.getTime();
- System.out.println((l2-l1)/(24*3600*1000));
- }
- }
复制代码 编译通过,运行报错:java.lang包下的空指针异常,38行和14行,请帮忙看看....谢谢 |