I'm getting a parse exception when trying to run
SimpleDateFormat format = new SimpleDateFormat("mm:ss", Locale.US);
String str = "11:22";
Date time = format.parse(str);
I haven't the foggiest what I'm doing wrong.
I'm getting a parse exception when trying to run
SimpleDateFormat format = new SimpleDateFormat("mm:ss", Locale.US);
String str = "11:22";
Date time = format.parse(str);
I haven't the foggiest what I'm doing wrong.
Try doing this bud and tell me whether it works for you or not!
Date dateInput;
String str = "11:22";
DateFormat inputFormat = new SimpleDateFormat("mm:ss");
try {
dateInput = inputFormat.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
Do you need the output too of the parsed date? If yes then tell me will update the answer. And if you still get the exception then try to print the log cat output which you'll find in this section.
Go below and check this out and copy paste the logcat.
If the beginning of the specified string cannot be parsed method parse
which is of DateFormat
class will generate ParseException.
So, We need to catch that exception. One of the method is given below in java code
import java.text.*;
import java.util.*;
public class Prg
{
public static void main(String args[]) throws Exception
{
SimpleDateFormat format = new SimpleDateFormat("mm:ss", Locale.US);
String str = "11:22";
Date time = format.parse(str);
System.out.println(time.toString());
}
}