[Solved] Parse a string without using SimpleDateFormat [closed]


Try approaching the problem as if the values you are trying to parse don’t represent a time. Instead, try to parse three separate values (hour, minute, AM/PM). How would you do that?

You know that the hour is two digits and ends with a ‘:’. So extract those two characters and parse as an int.

Then skip the ‘:’ and repeat for the minutes.

Finally, check if the last two characters are AM or PM.

Now that you have all the pieces, turn them into standard international time form.

Edit: If you are trying to be more efficient, there are shortcuts.

If the time is AM, and the hour is not 12, then the numbers will be identical. If the hours are 12, then change them to 00.

Otherwise if the time is PM, drop the last three characters and replace the first two digits with the current value + 12 (unless the hours were 12, in which case they should not be changed).

5

solved Parse a string without using SimpleDateFormat [closed]