I have a string like
8/29/2011 11:16:12 AM. I want to split that string into separate variables like
date = 8/29/2011
time = 11:16:12 AM
Why not to use DateFormat?
Check http://docs.oracle.com/javase/7/docs/api/java/text/DateFormat.html
String str = "8/29/2011 11:16:12 AM";
String fmt = "MM/dd/yyyy HH:mm:ss a";
DateFormat df = new SimpleDateFormat(fmt);
Date dt = df.parse(str);
DateFormat tdf = new SimpleDateFormat("HH:mm:ss a");
DateFormat dfmt = new SimpleDateFormat("MM/dd/yyyy");
String timeOnly = tdf.format(dt);
String dateOnly = dfmt.format(dt);
It gives more work/code but it's the proper way to do it.