JAVA 8 / CATATAN</>↗Java 817 Jan 2024
The TemporalAdjusters.firstDayOfMonth() method in Java is used to obtain a copy of the current date with the day set to the first day of the current month. This method is quite simple to use. You need to import the java.time package and use the with() function in conjunction with TemporalAdjusters.firstDayOfMonth(). Here’s a simple example in […]
JAVA 8 / CATATAN</>↗Java 817 Jan 2024
dayOfWeekInMonth() is a handy method in java.time.temporal.TemporalAdjusters class that returns an adjuster which changes the date to the n-th day of week in the current month. Here is an example of how you could use it: package org.kodejava.datetime; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.temporal.TemporalAdjusters; public class DayOfWeekInMonthExample { public static void main(String[] args) { // […]
JAVA 8 / CATATAN</>↗Java 817 Jan 2024
The java.time.temporal.TemporalAdjuster interface and the java.time.temporal.TemporalAdjusters class are both part of the Java Date-Time API, and they work together for adjusting temporal objects. TemporalAdjuster interface: This is a functional interface, which means it has only one abstract method, adjustInto(). This method is meant to adjust a temporal object, such as LocalDate, LocalDateTime, YearMonth, etc. The […]
JAVA 8 / CATATAN</>↗Java 817 Jan 2024
java.time.Duration is another useful class in Java for dealing with time. It measures time in seconds and nanoseconds and is most suitable for smaller amounts of time, like “20 seconds” or “3 hours”, and not for larger units like “3 days” or “4 months”. Here’s a guide on how to use it: 1. Creating a […]
JAVA 8 / CATATAN</>↗Java 817 Jan 2024
java.time.Period is a class that represents a quantity or amount of time in terms of years, months, and days. Here’s a brief guide on how to use it: 1. Creating a Period instance The Period class provides several static methods named of() and between() to create an instance. To create Period of 1 year, 2 […]
JAVA 8 / CATATAN</>↗Java 817 Jan 2024
ChronoUnit is an enumeration that provides static constants representing the units of time in the date-time API in Java. These constants include DAYS, HOURS, SECONDS, etc., that are often used to measure a quantity of time with respect to the specifics of a calendar system. Here’s an example of how you can use the ChronoUnit […]