Skip to content

Instantly share code, notes, and snippets.

@gauravkukade
Created May 15, 2021 11:16
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/ef36191b7cca3069631ab45918624c1c to your computer and use it in GitHub Desktop.
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/
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