tl;dr
Instant // Represent a moment in UTC, with a resolution of nanoseconds.
.now() // Capture the current moment as seen in UTC. Returns an `Instant` object.
.plus( // Add a span-of-time, resulting in a different moment.
Duration // Represent a span-of-time unattached to the timeline on the scale of hours-minutes-seconds.
.parse( "PT3H" ) // Parse a string in standard ISO 8601 format. Returns a `Duration` object.
) // Returns another `Instant` object.
Details
You seem to be unwisely mixing different kinds of data types.
LocalDateTime
represents a date and a time-of-day without a time zone or offset-from-UTC. So it cannot represent a moment. Do not use this class if you are tracking actual moments in time.
Date
, both java.util.Date
and java.sql.Date
, are terrible legacy classes that should never be used. They were supplanted by the modern java.time classes years ago with the adoption of JSR 310. Specifically, Instant
replaces the first, and LocalDate
replaces the second.
Duration
represents a span of days (in terms of 24-hour chunks of time, not calendar days), hours, minutes, seconds, and fractional second. For a span-of-time in terms of years-months-days, use Period
.
LocalDateTime.now()
I cannot think of any situation where this call is the right thing to do. As mentioned above, this class by definition cannot represent a moment. So trying to capture the current moment as LocalDateTime
is almost certainly the wrong thing to do.
Apparently you want to parse a string representing a number of hours-minutes-seconds. Easy to do if your input string is in standard ISO 8601 format.
String input = "PT4H30M" ; // Four-and-a-half hours.
Duration duration = Duration.parse( input ) ;
Then you apparently want to capture the current moment.
Instant instant = Instant.now() ; // Capture the current moment as seen in UTC.
And lastly you want to add the span-of-time to that current moment.
Instant later = instant.plus( duration ) ;
Generate a string in standard ISO 8601 format for this new moment.
String output = later.toString() ;