88import java .math .BigInteger ;
99import java .security .MessageDigest ;
1010import java .security .NoSuchAlgorithmException ;
11+ import java .time .Instant ;
12+ import java .time .format .DateTimeFormatter ;
13+ import java .time .temporal .TemporalAccessor ;
1114import java .util .concurrent .ThreadLocalRandom ;
12- import java .util .regex .Matcher ;
1315import java .util .regex .Pattern ;
1416
1517/**
@@ -30,6 +32,9 @@ public class StringUtils {
3032 private static final ThreadLocal <MessageDigest > LOCAL_HASH_MD =
3133 ThreadLocal .withInitial (StringUtils ::getHashMD5 );
3234
35+ private static final DateTimeFormatter TIMESTAMP_FORMETTER =
36+ DateTimeFormatter .ofPattern ("HH:mm:ss:SSS" );
37+
3338 /**
3439 * Return an empty string if the received string is null.
3540 *
@@ -51,10 +56,30 @@ public class StringUtils {
5156 return isEmpty (string ) ? another : string ;
5257 }
5358
59+ /**
60+ * Format a time to a string by pattern HH:mm:ss:SSS
61+ *
62+ * @param timestamp the timestamp.
63+ * @return the string presentation.
64+ */
65+ public static @ NotNull String formatTimestamp (long timestamp ) {
66+ return TIMESTAMP_FORMETTER .format (Instant .ofEpochMilli (timestamp ));
67+ }
68+
69+ /**
70+ * Format some temporal accessor to a string by pattern HH:mm:ss:SSS
71+ *
72+ * @param temporal the timestamp.
73+ * @return the string presentation.
74+ */
75+ public static @ NotNull String formatTimestamp (@ NotNull TemporalAccessor temporal ) {
76+ return TIMESTAMP_FORMETTER .format (temporal );
77+ }
78+
5479 /**
5580 * @see #isValidEmail(String)
5681 */
57- @ Deprecated
82+ @ Deprecated ( forRemoval = true )
5883 public static boolean checkEmail (@ NotNull String email ) {
5984 var matcher = EMAIL_PATTERN .matcher (email );
6085 return matcher .matches ();
0 commit comments