能不能将日期形式的字符串转成整数如:
String str = "2005-03-10";
请前辈们指教啊~

解决方案 »

  1.   

    可以的 但 - 是不能转成 整数   你用 split(“-”)分割成字符串数组 ,用 Integer.ValueOf(str);就行了
      

  2.   


    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar calendar = Calendar.getInstance();

    try {
    calendar.setTime(sdf.parse("2005-03-10"));
    System.out.println(calendar.get(Calendar.YEAR));
    } catch (ParseException e) {
    e.printStackTrace();
    }年 月 日 依次取就是了
      

  3.   

    字符串分割,然后加到StringBuffer中
      

  4.   


    str  =str.replaceAll("-","");
    Long long = Long.parseLong(str);