Reputation: 23
I'm trying to use Java time to format a date in a particular way so that I can search for the date in a text file. I've imported java.time.format.DateTimeFormatter but when I enter the code
DateTimeFormatter formatDate = new DateTimeFormatter.ofPattern("dd/MM/yyyy");
it displays the error "Cannot resolve symbol ofPattern". I can't see what I'm doing wrong so any help would be greatly appreciated! Thanks
Upvotes: 2
Views: 2668
Reputation: 1885
There are two issues in this snippet:
ofPattern
taking zero arguments. According javadoc you should use either ofPattern(String pattern)
, either ofPattern(String pattern, Locale locale)
Bringing all the things together
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd");
Hope it helps!
Upvotes: 7