Created
May 15, 2021 11:16
-
-
Save gauravkukade/ef36191b7cca3069631ab45918624c1c to your computer and use it in GitHub Desktop.
A java program to get local date time using the java.time.LocalDateTime 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.LocalDateTime; | |
import java.time.format.DateTimeFormatter; | |
/** | |
* A java program to get local date time using the java.time.LocalDateTime class | |
* @author Gaurav Kukade at coderolls.com | |
*/ | |
public class LocalDateTimeExample { | |
public static void main(String[] args) { | |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); | |
LocalDateTime localDateTime = LocalDateTime.now(); | |
// print localDateTime object | |
System.out.println(localDateTime); // 2021-05-15T13:20:13.329481722 | |
// print formatted localDateTime | |
System.out.println(dateTimeFormatter.format(localDateTime)); //15/05/2021 13:20:13 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment