Problem with year

Discussion in 'Programming' started by ssimon171078, Aug 21, 2014.

  1. #1
    i need to exract year and save to int.i wrote code in java someone can help me?
    public void setAge(String date) {
    if(date!=null){
    String format="yyyy/MM/dd";
    SimpleDateFormat sdf=new SimpleDateFormat(format);
    String bDate="1975/03/11";
    System.out.println(bDate);
    }
    }








    }
    }
     
    ssimon171078, Aug 21, 2014 IP
  2. Joel Meijering

    Joel Meijering Member

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #2
    You could split into substrings, and convert the first item to int as follows (copy this code under your code):

    String[] parts = bDate.split("/");
    String yearString = parts[0];
    int yearInt = Integer.parseInt(yearString);
     
    Joel Meijering, Sep 3, 2014 IP