我得到了LocalDateTime从 . 创建的对象String。我想检查原始字符串是否有“秒”参数。我的两个输入是:
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);
Run Code Online (Sandbox Code Playgroud)
问题是我给出的是dateA和dateB,而不是a和b。
我尝试了各种方法,例如转换LocalDateTime为String并找到其长度。为此我使用了两种方法。
date.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME).length();
date.toString().length();
Run Code Online (Sandbox Code Playgroud)
dateA但第一种方法为和提供长度 19 ,而第二种方法为和dateB 提供长度 16 。dateAdateB
我无法找到任何方法来区分dateA和dateB。