First of all, the parenthesis around
LocalDateTime.now() are useless.
Now, let's see what we're really doing here:
We're creating a unique
LocalDateTime each time, but I am assuming that you always use the same
format, and therefore the
DateTimeFormatter.ofPattern(format) object will always be the same.
I would recommend not creating a method for this and instead extract a constant for the format:
private static final DateTimeFormatter FORMAT = DateTimeFormatter.ofPattern("ssmmHHddMMMuu");
And then each time you need it, you just do
A method named
getTodaysDateInFormat provides exactly the same information as the above piece of code, therefore the method does not really provide any additional value.
I don't consider
LocalDateTime.now().format(FORMAT) as duplicated code. Or rather: I'm considering just as much code duplication as a call to