Skip to content

Instantly share code, notes, and snippets.

@berensn
Last active November 7, 2018 02:34
Show Gist options
  • Save berensn/a2286d62937b56020d8ea27e0705634c to your computer and use it in GitHub Desktop.
Save berensn/a2286d62937b56020d8ea27e0705634c to your computer and use it in GitHub Desktop.
Java DateTime w/ custom formatting
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));
}
}
@berensn
Copy link
Author

berensn commented Nov 7, 2018

Prints a timestamp in the format [2018-11-6 21:32:52]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment