How to get start and end range from list of timestamps?

OffsetDateTime

Parse those ISO 8601 strings into java.time.OffsetDateTime objects.

OffsetDateTime.parse( "2016-01-15T00:44:59+08:30" )

Add those date-time objects to a Collection and sort. You probably want a List such as ArrayList or a SortedSet.

The java.time classes implement the compareTo method, to fulfill their contract as a Comparable. So these objects know how to sort.

Like this:

List<OffsetDateTime> odts = new ArrayList<>();

OffsetDateTime odt = OffsetDateTime.parse( "2016-01-15T00:44:59+08:30" ) ;
odts.add( odt );
… // Parse remaining ISO 8601 strings, adding each new OffsetDateTime object to collection.

Collections.sort( odts );

Leave a Comment