SoFunction
Updated on 2025-04-11

java LocalDateTime plus time, calculate the difference between two times

java LocalDateTime plus time, calculate two time difference

 LocalDateTime localDateTime = ();
 localDateTime= (1);//Add one day

Calculate the difference between two times

("Calculate the difference between two times:");
        String time2 = "2020-06-26 19:00:00";
        String time1 = "2020-06-26 19:00:30";

        DateTimeFormatter dtf2 = ("yyyy-MM-dd HH:mm:ss");
        LocalDateTime end = (time1, dtf2);
       // LocalDateTime end = ();
        //LocalDateTime now = ();
        LocalDateTime now = (time2, dtf2);
        Duration duration = (now,end);
        long days = (); //The number of days difference        long hours = ();//The difference in hours        long minutes = ();//The difference in minutes        long millis = ();//The difference in milliseconds        long nanos = ();//The difference in nanoseconds        (now);
        (end);

        ("Send text messages takes time [ "+days+"sky:"+hours+" Hour:"+minutes+" minute:"+millis+" milliseconds:"+nanos+"Nanosec");

Calculate the difference between two times

Send text messages time [0 days: 0 hours: 0 minutes: 30000 milliseconds: 3000000000000 nanoseconds]

Make a comparison

        String time1 = "2019-06-26 19:00:00";
        DateTimeFormatter dtf2 = ("yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = (time1, dtf2);
        ((()));//Your time is true before the current time        ((()));//After the current timefalse

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.