I am given LocalDateTime
object created from String
. I want to check whether that original string has "seconds" parameter or not.
My two inputs are:
String a = "2016-06-22T10:01"; //not given
String b = "2016-06-22T10:01:00"; //not given
LocalDateTime dateA = LocalDateTime.parse(a, DateTimeFormatter.ISO_DATE_TIME);
LocalDateTime dateB = LocalDateTime.parse(b, DateTimeFormatter.ISO_DATE_TIME);
Problem is I am given dateA
and dateB
, not a
and b
.
I have tried various ways like converting LocalDateTime
to String
and finding its length. For that I used two approaches.
date.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME).length();
date.toString().length();
But first approach gives length 19 for both dateA
and dateB
whereas second approach gives length 16 for both dateA
and dateB
.
I am unable to find any way to differentiate dateA
and dateB
.
LocalDateTime
s, since missing seconds mean that they're zero. – Gardening