-3

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.

Tim
  • 1
  • 2
  • 4
    You need to show us the error details - post your logcat output. Then explain what research you did on that exception and what exact confusion you had about what you read. – takendarkk Oct 05 '17 at 18:36
  • as @csm_dev said, can you post your logcat? You might want to take a look at [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Drew Szurko Oct 05 '17 at 18:39
  • My logcat didn't have any traces because it wasn't throwing exceptions because I didn't have my parsing in a try/catch block. Specifically, what I didn't understand was the concept of [checked exceptions](https://stackoverflow.com/questions/9371686/what-are-checked-exceptions-in-java-c). – Tim Oct 05 '17 at 23:44

2 Answers2

0

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.

enter image description here

Alok
  • 8,452
  • 13
  • 55
  • 93
0

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());
       }

}
M.Usman
  • 2,049
  • 22
  • 25