Friday, October 22, 2021

Formatting a Date in Java

For some reason my installation of Java wouldn't let me use SimpleDateFormat to format my dates. So I had to google a different way to do this and found the following works as well. The Date class has a bunch of issues with it to begin with, so this is much cleaner and better as well.


LocalDateTime ldt = LocalDateTime.now();
DateTimeFormatter df = DateTimeFormatter.ofPattern("MM/dd/yyyy", Locale.ENGLISH);
String formattedString = df.format(ldt);

No comments:

Post a Comment

Ever feel like no one is listening?

 Ever have that feeling that no one is listening to you? Yeah, that feeling. It can be a strong feeling to have, a hurtful feeling also. The...