In this article, we will find the day of the week using the date in Java. From Java 8, the java.time package provides the date and time functionalities. To see the day of the week, we can use the LocalDate…
Programming
In this article, we will see how to cache the HTTP response and use the cached response when the user is offline using Retrofit and OkHttp. OkHttp provides built-in support for caching HTTP responses. To enable caching in Retrofit, we…
In this article, we will see how to pretty print a map in Java and make it easier to visualize the key-value pairs. Let us first create an example map to show how to do a pretty print of the…
In this article, we will see how to find if the given substring is present in the entire string or not. Java’s java.util.regex package provides classes such as Pattern and Matcher to perform the substring matching. First, import the required…
In this article, we will see how to generate a random date between two dates in Java. In Java, we can use the java.time.LocalDate to represent a date without a time component and this along with java.time.temporal.ChronoUnit we can calculate…
In this article, we will see how to implement random sleep in Java which helps to avoid synchronization issues and make the behaviour of concurrent programs less predictable. Using the java.util.Random class, we can generate random values and these random…
Calculating the age is a common requirement in many applications as it is used for age verification and for providing personalized experiences. In this article, we will see how to calculate a person’s age using their date of birth in…
In many scenarios, it is necessary to calculate the number of days between two given dates. For example, to find the duration between two events, calculate the age of a person. Using the java’s powerful date and time functionalities we…
Converting local time to UTC is crucial when building an application which is used by users thought the world, particularly for accurate time calculations and data storage. In this article, we will see the step-by-step procedure of how to convert…
In this article, we will see how to convert the date from one timezone to another. Timezones are regions of the world with the same standard time. In Java, timezones are represented by the ZoneId class. In Java, we have…