I am learning java, trying to build a tool to convert a specific time from timezone A to timezone B based on user input (input of the time, timezone A, and timezone B). This is about the part where the tool gathers a time in a specific format to convert it into a ZonedDateTime object.
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
public static String fullTime;
public static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm a");
public static ZonedDateTime newTime;
public static void getHourAndMinutes(){
System.out.print("Please type in the time you have in mind in format hh:mm am/pm\n");
Scanner in = new Scanner(System.in);
fullTime = in.nextLine();
System.out.println(fullTime);
newTime = ZonedDateTime.parse(fullTime, formatter);
I have tried to enter the time in formats like 10:30PM, 10:30 PM, 10:30pm, 10:30 pm, 10:30p, 10:30 p, all of these entries has caused exception error to be thrown, I'm getting errors like this one
Exception in thread "main" java.time.format.DateTimeParseException: Text '10:30 pm' could not be parsed at index 6
Any idea what I might be doing wrong? Thanks!