tl;dr
Convert from legacy class to modern class. Adjust from UTC to a time zone. Generate text in standard ISO 8601. We omit the context of time zone or offset in our output because you so requested, against my recommendation.
myJavaUtilDate
.toInstant()
.atZone( ZoneId.of( "Asia/Kolkata" ) )
.truncatedTo( ChronoUnit.MINUTES )
.format( DateTimeFormatter.ISO_LOCAL_DATE_TIME )
I expect using UTC and including the offset would be wiser.
myJavaUtilDate
.toInstant()
.toString()
Details
Date-time objects do not have a format, only text has a format.
Use java.time classes, never java.util.Date
.
Convert your legacy Date
object to its modern replacement, java.time.Instant
.
Instant instant = myJUDate.toInstant() ;
Adjust from UTC to your desired time zone.
ZoneId z = ZoneId.of( "Asia/Kolkata" ) ;
ZonedDateTime zdt = instant.atZone( z ) ;
Apparently you do not care about the the second of minute. So let’s truncate that to zero seconds.
ZonedDateTime zdt = zdt.truncatedTo( ChronoUnit.MINUTES ) ;
Generate text in your desired format. Java comes bundled with a formatter already defined for your format.
String output = zdt.format( DateTimeFormatter.ISO_LOCAL_DATE_TIME ) ;
I showed that format because asked. But I do not recommend it. That format fails to indicate a time zone or offset-from-UTC. So if it says noon, the reader does not know if that means noon in Tokyo Japan