Skip to content

Instantly share code, notes, and snippets.

@gauravkukade
Created May 15, 2021 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gauravkukade/4a756785c65e94fa645c1a4faa65edb4 to your computer and use it in GitHub Desktop.
Save gauravkukade/4a756785c65e94fa645c1a4faa65edb4 to your computer and use it in GitHub Desktop.
A java program to get local date using the java.time.LocalDate class. Check the blog post at https://coderolls.com/get-current-date-time-in-java/
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* A java program to get local date using the java.time.LocalDate class
* @author Gaurav Kukade at coderolls.com
*/
public class LocalDateExample {
public static void main(String[] args) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
LocalDate localDate = LocalDate.now();
// print localDate object
System.out.println(localDate); // 2021-05-15
// print formatted localDate
System.out.println(dateTimeFormatter.format(localDate)); // 2021/05/15
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment