java.time either through desugaring or through ThreeTenABP
It seems that you have received a string where someone has misunderstood the ISO 8601 standard and given you a string representing a duration where they intended a time of day.
I recommened you use java.time, the modern Java date and time API, for your time work. The problem with the incorrect string can be solved by regarding it as a duration since 00:00.
    DateTimeFormatter formatter
            = DateTimeFormatter.ofPattern("h:mm a", Locale.ENGLISH);
    
    String docTimeString = "PT18H30M";
    
    Duration docTimeDur = Duration.parse(docTimeString);
    LocalTime docTimeOfDay = LocalTime.MIDNIGHT.plus(docTimeDur);
    String humanReadableDocTime = docTimeOfDay.format(formatter);
    
    System.out.println(humanReadableDocTime);
Output:
6:30 PM
I am exploiting the fact that Duration.parse() expects and parses ISO 8601 format.
"Call requires API level 26 (current min is 16): java.time.Duration#parse" showing this
java.time works nicely on both older and newer Android devices. It just requires at least Java 6.
- In Java 8 and later and on newer Android devices (from API level 26) the modern API comes built-in.
- In non-Android Java 6 and 7 get the ThreeTen Backport, the backport of the modern classes (ThreeTen for JSR 310; see the links at the bottom).
- On older Android either use desugaring or the Android edition of ThreeTen Backport. It’s called ThreeTenABP. In the latter case make sure you import the date and time classes from org.threeten.bpwith subpackages.
Links