Created
May 15, 2021 11:13
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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