0

The issue is that I want to pass this code that is in Java 8 to Java 7 but I have no idea, I don't want to use a library to be able to pass it, but what would be the equivalent code in Java 7. Any suggestions?

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
String fecha = LocalDate.now().format(formatter);
efejdlek
  • 39
  • 10
  • Either look into https://www.threeten.org/threetenbp/ which is a backport of the Java 8 time library for Java 7 or you actually have to convert to the old legacy date classes like `Date`, `Calendar`, `SimpleDateFormatter` which you seriously should avoid. – Zabuzard Jan 26 '21 at 14:59
  • 1
    Yeah , but it's for an old program – efejdlek Jan 26 '21 at 15:01

1 Answers1

2

In java 7, you can use SimpleDateFormat to handle this.

new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
  • Yes, I'm wondering why the comment to "seriously avoid" `SimpleDateFormatter` was made. – markspace Jan 26 '21 at 15:20
  • Well, it seems that SimpleDateFormatter is not thread safe, so if you use this in a static context, your application will have a problem dealing with multiple actions to format your dates – Leonardo Gasparini Jan 26 '21 at 15:28
  • The documentation says: `Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.` So all that is required is to synchronize externally. – markspace Jan 26 '21 at 18:51