i have project in android, and i need split string, which is actually date here is the String that i'm going to split:
String datetime = "01/03/2013 09:00";
and this is how i call them:
int year = splitDateTime(dateTime)[0];
public int[] splitDateTime(String datetime){
String date_time = datetime;
String delimiter = "//:";
String[] sParts;
int[] intParts;
sParts = date_time.split(delimiter);
intParts = new int[sParts.length];
for(int i =0; i < sParts.length ; i++)
intParts[i] = Integer.parseInt(sParts[i]);
return intParts;
}
but it keeps giving me an error, so i would be happy if you help me out guys. cheers
I bet you mean something like:
String datetime = "01/03/2013 09:00";
String[] sParts = datetime.split("[/:\\s+]");
int[] iParts = new int[sParts.length];
for(int i = 0; i < sParts.length; i++)
iParts[i] = Integer.parseInt(sParts[i]);
System.out.println(Arrays.toString(iParts));
OUTPUT:
[1, 3, 2013, 9, 0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With