Last active
November 7, 2018 02:34
-
-
Save berensn/a2286d62937b56020d8ea27e0705634c to your computer and use it in GitHub Desktop.
Java DateTime w/ custom formatting
This file contains hidden or 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.*; | |
import java.time.format.DateTimeFormatter; | |
public class TimeTravel | |
{ | |
public static void main (String[] args) | |
{ | |
LocalDateTime ldt = LocalDateTime.now(); | |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | |
String time = formatter.format(ldt); | |
System.out.println(String.format("[%s]", time)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prints a timestamp in the format [2018-11-6 21:32:52]