Java Local Date Time: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<source lang="java"> | <source lang="java"> | ||
import java.time.LocalDateTime; | import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | import java.time.format.DateTimeFormatter; | ||
Line 7: | Line 5: | ||
class Playground { | class Playground { | ||
public static void main(String[ ] args) { | public static void main(String[] args) { | ||
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); | DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); | ||
LocalDateTime endDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).plusHours(23).minusNanos(1L); | LocalDateTime endDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).plusHours(23).minusNanos(1L); | ||
Line 21: | Line 19: | ||
{| | {| | ||
| valign="top" | | | valign="top" | | ||
* [https://www.timeanddate.com/worldclock/malaysia/kuala-lumpur World Clock Kuala Lumpur, Malaysia] | |||
* [https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html Java » ISO <code>DateTimeFormatter</code>] | |||
* [https://www.timeanddate.com/worldclock/bangladesh/dhaka World Clock Dhaka, Bangladesh] | |||
* [https://code.sololearn.com/cVRUy2BwauK8 Java Playground Online] | * [https://code.sololearn.com/cVRUy2BwauK8 Java Playground Online] | ||
| valign="top" | | |||
| valign="top" | | | valign="top" | | ||
|} | |} |
Latest revision as of 18:08, 1 February 2024
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));
}
}