Last active
June 27, 2021 09:46
-
-
Save pythoncat1024/f7c5d0ad51ae7a3df4b1e98ff762b491 to your computer and use it in GitHub Desktop.
show current time string like '2021-06-27 17:41:16.681'
This file contains 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
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