Languages
[Edit]
EN

Java date time now with milliseconds - yyyy-MM-dd HH:mm:ss.milliseconds or yyyy_MM_dd__HH_mm_ss_milliseconds (java time SSS format)

5 points
Created by:
illona
526

Quick solution:

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class JavaDateTimeNowExamples {

    public static String createDateTimeNowMs() {
        // 2021_05_15__12_29_12_627
        return DateTimeFormatter.ofPattern("yyyy_MM_dd__HH_mm_ss_SSS")
                .format(LocalDateTime.now());
    }

    public static String createDateTimeNow() {
        // 2021_05_15__12_29_12
        return DateTimeFormatter.ofPattern("yyyy_MM_dd__HH_mm_ss")
                .format(LocalDateTime.now());
    }

    public static void main(String[] args) {

        System.out.println(createDateTimeNowMs()); // 2021_05_15__12_29_12_627
        System.out.println(createDateTimeNow());   // 2021_05_15__12_29_12
    }
}

Output:

2021_05_15__12_29_12_627
2021_05_15__12_29_12

 

Alternative titles

  1. java time SSS
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join