Skip to content

Instantly share code, notes, and snippets.

@austintraver
Last active July 15, 2020 20:43
Show Gist options
  • Save austintraver/d2ecb2d04e451e54128b67fcfa42ccb6 to your computer and use it in GitHub Desktop.
Save austintraver/d2ecb2d04e451e54128b67fcfa42ccb6 to your computer and use it in GitHub Desktop.
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class Timer {
public static void main(String[] args) {
/* Get the current time */
LocalTime localTime = LocalTime.now();
/* Specify the formatting for the timestamp string */
/* Read this Java documentation link to understand! */
/* https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html */
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss.SS");
/* Generate the formatted timestamp string */
String timestamp = String.format("[%s]", dateTimeFormatter.format(localTime));
/* Print the formatted timestamp string */
System.out.println(timestamp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment