+ 4

Date and time setting

How to parse date and time to String

26th Jul 2020, 4:39 PM
Imaddean Nsubuga
Imaddean Nsubuga - avatar
2 Answers
+ 1
import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; .. LocalDateTime dt = LocalDateTime.now(); var form1 = DateTimeFormatter .ofPattern("dd.mm.yy HH:mm:ss"); //HH 24h var form2 = DateTimeFormatter .ofLocalizedDateTime(FormatStyle.SHORT); System.out.println(form1.format(dt) ); System.out.println(form2.format(dt) );
26th Jul 2020, 9:32 PM
zemiak
+ 3
There are various libraries you could use to do so... LocalDate, LocalDateTime and DateTimeFormatter are part of standard libs and provide everything you could need.
26th Jul 2020, 4:44 PM
Sandra Meyer
Sandra Meyer - avatar