In case someone reads this or uses Java 8 or later or works fine with a (good and future) external library:
DateTimeFormatter noSeconds = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT) .withLocale(Locale.ITALY); LocalTime time = LocalTime.now(ZoneId.systemDefault()); System.out.println(time.format(noSeconds));
This is just printed:
15.26
Please replace the desired locale instead of Locale.ITALY . Use Locale.getDefault() to configure the JVM locale. I believe that it prints without seconds in all locales.
I used the LocalTime object in the LocalTime , but the same code works for many other date and time classes, including LocalDateTime , OffsetDateTime , OffsetTime and ZonedDateTime .
To use DateTimeFormatter and any of the other classes mentioned on Android, you will need ThreeTenABP . Learn more about how in this question: how to use ThreeTenABP in Android Project . For any non-Android Java 6 or 7, use ThreeTen Backport .
source share