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