Skip to content

Instantly share code, notes, and snippets.

@JoaquimLey
Last active August 14, 2016 14:02
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 JoaquimLey/a25d737e9c6f671bcfc4 to your computer and use it in GitHub Desktop.
Save JoaquimLey/a25d737e9c6f671bcfc4 to your computer and use it in GitHub Desktop.
Get current DAY_MONTH_YEAR_HOUR_MINUTES_SECONDS
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH); // Note: Starts at 0
int day = now.get(Calendar.DAY_OF_MONTH);
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
int second = now.get(Calendar.SECOND);
int millis = now.get(Calendar.MILLISECOND);
// NOTE: Starts at 0, hence month + 1
System.out.printf("%d-%02d-%02d %02d:%02d:%02d.%03d", year, month + 1, day, hour, minute, second, millis);
// Prints: 2010-04-16 11:15:17.816
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment