The problem is for Java
I want to take time input as follows
12:00 AM 11:42 PM
There will be a sequence of such inputs up to N
lines.
Here two different Time Inputs are given
1)12:00 AM
2)11:42 PM
but they are in the same line.
The time inputs are for a single person entering(12:00 AM) and leaving(11:42 PM)
I know SimpleDateFormat
but I can't modify it to suit my needs as said.
So please help
java.time and a regular expression
I recommend that you use java.time, the modern Java date and time API, for your time work. There are different ways to split the string into two to separate the two times in it; I too go for a regular expression.
String.split()
accepts one.Output from this snippet is:
The regular expression
(?<=M)
matches a space preceded by an upper caseM
, so this is where the input string is being split.Link: Oracle tutorial: Date Time explaining how to use java.time.