Reputation: 2540
I will get Date
in string format like 11/01/2017
. From that string I want to take only the year. Like
String stringDate="11/01/2017";
the output I want is just "2017
";
How to split that string?
Thanks in advance.
Upvotes: 1
Views: 115
Reputation: 4672
If you have a String and will always be dd/mm/yyyy, then you can simply do:
dateString.substring(6)
Upvotes: 2
Reputation: 312
You can use this as well.
String input="11/1/2017";
String year=input .substring(input .length()-4);
Upvotes: 2
Reputation: 521997
One option would be to split on forward slash and retain the third part:
String input = "11/01/2017";
String year = input.split("/")[2];
Upvotes: 3