I have the String = "08/21/2018"
.
How can I get only "08"
from this line and insert this value into a int
?
FInal result must be int month = 01
.
I have the String = "08/21/2018"
.
How can I get only "08"
from this line and insert this value into a int
?
FInal result must be int month = 01
.
You need to split string and need to get 0 index value and parse that in an integer value.As shown in below code.
String date = "08/21/2018";
String [] splitDate = date.split("/");
int month = Integer.valueOf(splitDate[0]);
String date= "08/21/2018";
String[] arr=date.split(Pattern.quote("/"));
int month = Integer.parseInt(arr[0]);
int day = Integer.parseInt(arr[1]);
int year = Integer.parseInt(arr[2]);