Skip to content

Instantly share code, notes, and snippets.

@pythoncat1024
Last active June 27, 2021 09:46
Show Gist options
  • Save pythoncat1024/f7c5d0ad51ae7a3df4b1e98ff762b491 to your computer and use it in GitHub Desktop.
Save pythoncat1024/f7c5d0ad51ae7a3df4b1e98ff762b491 to your computer and use it in GitHub Desktop.
show current time string like '2021-06-27 17:41:16.681'
private static String time() {
Calendar instance = Calendar.getInstance();
int year = instance.get(Calendar.YEAR);
int month = instance.get(Calendar.MONTH) + 1;
int day = instance.get(Calendar.DAY_OF_MONTH);
int hour = instance.get(Calendar.HOUR_OF_DAY);
int minute = instance.get(Calendar.MINUTE);
int second = instance.get(Calendar.SECOND);
int millis = instance.get(Calendar.MILLISECOND);
return String.format(Locale.CHINA, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
year, month, day, hour, minute, second, millis);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment