Java Local Date Time: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
(Created page with "<source lang="java"> import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.tempora...")
 
No edit summary
Line 17: Line 17:
}
}
</source>
</source>
==References==
{|
| valign="top" |
* [https://code.sololearn.com/cVRUy2BwauK8 Java Playground Online]
| valign="top" |
|}

Revision as of 02:46, 29 July 2021

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

class Playground {
    public static void main(String[ ] args) {
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
        LocalDateTime    endDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).plusHours(23).minusNanos(1L);
        LocalDateTime  startDate = endDate.minusDays(1).plusNanos(1L);

        System.out.println("Start Date: " + startDate.format(format));
        System.out.println("end   Date: " +   endDate.format(format));
    }
}

References