DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Adrian Matei for Codever

Posted on • Updated on • Originally published at codever.land

How to get date or datetime from string in java

To get the date or dateime from String since Java 8 you can use the parse method of both LocalDate and LocalDateTime which takes two parameters: the string and a DateFormatter which you can specify as in the following example:

LocalDate date = LocalDate.parse("1969-12-31", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
LocalDateTime dateTime = LocalDateTime.parse("1983-01-08 20:54", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
Enter fullscreen mode Exit fullscreen mode

Shared with โค๏ธ from Codever. ๐Ÿ‘‰ ย  use the copy to mine functionality to add it to your personal snippets collection.

Top comments (0)

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. ๐Ÿ›