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); } } } }
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);