So I've created a function to check my Date string for what month it contains - So that I can use this for multiple formats of dates (Before Soritios comes and tells me I'm a retard). But I'm using a lot of ifs and repeating the .contains function and it makes me want to puke. Is there a better way of doing this?
Also related my dates are in the format Weekday(String), Month(String) day(int- XX), Year(Int - XXXX). e.g. Sunday, June 27, 1965. I've had no luck so far with the built in functions.
public static int CheckMonth(String s){
String month = s.toLowerCase();
if(month.contains("january")){return 1;}
else if(month.contains("febuary")){return 2;}
else if(month.contains("march")){return 3;}
else if(month.contains("april")){return 4;}
else if(month.contains("may")){return 5;}
else if(month.contains("june")){return 6;}
else if(month.contains("july")){return 7;}
else if(month.contains("august")){return 8;}
else if(month.contains("september")){return 9;}
else if(month.contains("october")){return 10;}
else if(month.contains("november")){return 11;}
else if(month.contains("december")){return 12;}
else {return -1;}
}
Aucun commentaire:
Enregistrer un commentaire