Quantcast
Channel: How to get current timestamp in string format in Java? "yyyy.MM.dd.HH.mm.ss" - Stack Overflow
Viewing all articles
Browse latest Browse all 12

Answer by gzc for How to get current timestamp in string format in Java? "yyyy.MM.dd.HH.mm.ss"

$
0
0

Use modern java.time classes if you use java 8 or newer.

String s = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());

Basil Bourque's answer is pretty good. But it's too long. Many people would have no patience to read it. Top 3 answers are too old and may mislead Java new bee .So I provide this short and modern answer for new coming devs. Hope this answer can reduce usage of terrible SimpleDateFormat.


Viewing all articles
Browse latest Browse all 12

Trending Articles