Author name: Ramesh Fadatare

Java 8 – Convert LocalDateTime to ZonedDateTime

Introduction Java 8 introduced a new date and time API in the java.time package, which allows for more effective handling of dates and times. One common task is converting a LocalDateTime to a ZonedDateTime. A LocalDateTime represents a date and time without a time zone, while a ZonedDateTime includes the time zone information. Converting a …

Java 8 – Convert LocalDateTime to ZonedDateTime Read More »

Java 8 – Convert LocalDateTime to Epoch Milliseconds

Introduction In Java 8, when dealing with date and time, you may encounter situations where you need to convert a LocalDateTime object into the number of milliseconds since the Unix epoch (January 1, 1970, 00:00:00 GMT). This is often required when interfacing with systems that represent time as a long value or for storing date …

Java 8 – Convert LocalDateTime to Epoch Milliseconds Read More »

Java – Format LocalDateTime to dd/MM/yyyy HH:mm:ss

Introduction When working with date and time values in Java, you might need to format a LocalDateTime object into a specific string format, such as dd/MM/yyyy HH:mm:ss. This format is commonly used in many applications, especially in regions that follow the day-month-year convention. Java 8’s java.time package provides a powerful DateTimeFormatter class that makes formatting …

Java – Format LocalDateTime to dd/MM/yyyy HH:mm:ss Read More »

Java – Format LocalDateTime to dd-MM-yyyy HH:mm:ss

Introduction When working with both date and time values in Java, you often need to format a LocalDateTime object into a specific string format, such as dd-MM-yyyy HH:mm:ss. This format is commonly used in many applications for displaying or logging both date and time together. Java 8’s java.time package provides a powerful DateTimeFormatter class that …

Java – Format LocalDateTime to dd-MM-yyyy HH:mm:ss Read More »

Java – Format LocalTime to HH:mm:ss

Introduction When working with time values in Java, you might need to format a LocalTime object into a specific string format, such as HH:mm:ss. This format represents hours, minutes, and seconds, and is commonly used in various applications, particularly for displaying or logging time values. Java 8’s java.time package provides the DateTimeFormatter class, which makes …

Java – Format LocalTime to HH:mm:ss Read More »

Java – Format LocalDate to dd-MM-yyyy

Introduction When working with dates in Java, you often need to display a LocalDate in a specific format, such as dd-MM-yyyy. This format is commonly used in many applications, particularly in regions that follow the day-month-year convention. Java 8’s java.time package provides a powerful DateTimeFormatter class that makes formatting dates easy and intuitive. In this …

Java – Format LocalDate to dd-MM-yyyy Read More »

Java 8 – Get the First Day of the Month

Introduction Java 8 introduced the java.time package, which provides a modern and intuitive API for working with dates and times. A common requirement is to determine the first day of a given month, which can be useful in various applications, such as generating monthly reports, setting billing cycles, or scheduling events. Java 8’s LocalDate class …

Java 8 – Get the First Day of the Month Read More »

Java 8 – How to Add Hours to Time

Introduction Java 8 introduced the java.time package, which provides a modern and robust API for handling dates and times. Adding hours to a specific time is a common requirement, whether you’re scheduling events, calculating deadlines, or adjusting timestamps. Java 8’s LocalTime, LocalDateTime, and ZonedDateTime classes make it easy to add hours to a time value. …

Java 8 – How to Add Hours to Time Read More »

Java 8 – Format LocalDate to dd/MM/yyyy

Introduction Java 8 introduced the java.time package, which provides a modern and flexible way to work with dates and times. One common requirement is formatting a LocalDate object to a specific string format, such as dd/MM/yyyy. This format is widely used, particularly in countries that follow the day-month-year convention. In this guide, we’ll explore how …

Java 8 – Format LocalDate to dd/MM/yyyy Read More »

Java 8 – Get the Current Timestamp

Introduction Java 8 introduced the java.time package, which provides a modern and robust API for working with dates and times. A common requirement in many applications is obtaining the current timestamp, which represents the current date and time in a precise and standardized format. In Java 8, getting the current timestamp is straightforward, and it …

Java 8 – Get the Current Timestamp Read More »

Java 8 – Convert Instant to LocalDateTime

Introduction Java 8 introduced the java.time package, providing a modern way to work with dates and times. One common task is converting an Instant to a LocalDateTime. An Instant represents a specific moment in time, typically used for timestamps, while LocalDateTime represents a date and time without any time zone information. To convert an Instant …

Java 8 – Convert Instant to LocalDateTime Read More »

Java 8 – How to Add Days to the Current Date

Introduction Java 8 introduced the java.time package, which provides a modern and powerful way to work with dates and times. One common task in many applications is adding a certain number of days to the current date. Whether you’re calculating a future deadline, scheduling events, or determining expiry dates, Java 8 makes this easy with …

Java 8 – How to Add Days to the Current Date Read More »

Java 8 – Convert LocalDateTime to Timestamp

Introduction In Java 8, the java.time package introduced new classes to handle date and time more effectively. One common requirement is converting a LocalDateTime object to a Timestamp object, which is useful when working with databases that expect a Timestamp format. The Timestamp class is part of the older java.sql package, and converting between these …

Java 8 – Convert LocalDateTime to Timestamp Read More »

Java 8 – Difference Between Two Dates

Introduction Java 8 introduced the java.time package, which offers a modern and intuitive way to handle dates and times. Calculating the difference between two dates is a common task in many applications, whether you’re measuring the time elapsed between two events or calculating someone’s age. The java.time API makes these calculations straightforward and accurate, allowing …

Java 8 – Difference Between Two Dates Read More »

Java 8 – How to Get the Start and End of the Day

Introduction Java 8 introduced the java.time package, which provides a modern and intuitive way to handle dates and times. One common task in date and time manipulation is determining the start and end of a day. The LocalDate, LocalTime, and LocalDateTime classes in Java 8 make it easy to calculate the exact beginning and end …

Java 8 – How to Get the Start and End of the Day Read More »

Java 8 – Convert Between Time Zones

Introduction Java 8 introduced the java.time package, which provides a modern, robust API for working with dates and times. One common task when working with date and time is converting between different time zones. Java 8 makes this straightforward with classes like ZonedDateTime, ZoneId, and OffsetDateTime. These classes allow you to seamlessly convert date and …

Java 8 – Convert Between Time Zones Read More »

Java 8 – Convert LocalDateTime to LocalDate

Introduction Java 8 introduced the java.time package, which provides a modern approach to handling dates and times. The LocalDateTime class represents both date and time, while the LocalDate class represents just the date without any time information. There are scenarios where you may have a LocalDateTime object but need to extract just the date part. …

Java 8 – Convert LocalDateTime to LocalDate Read More »

Java 8 – Convert LocalDate to LocalDateTime

Introduction Java 8 introduced the java.time package, which offers a modern and intuitive approach to handling dates and times. The LocalDate class represents a date without time, while the LocalDateTime class represents both date and time. In many scenarios, you may start with a LocalDate and need to convert it to a LocalDateTime by adding …

Java 8 – Convert LocalDate to LocalDateTime Read More »

Java 8 – Add or Subtract Days, Months, and Years

Introduction Java 8 introduced the java.time package, which provides a modern approach to handling dates and times. One common task in date manipulation is adding or subtracting days, months, or years from a given date. The LocalDate, LocalTime, and LocalDateTime classes in Java 8 make these operations straightforward and intuitive. In this guide, we’ll explore …

Java 8 – Add or Subtract Days, Months, and Years Read More »

Scroll to Top