Converting Date instance to Instant instance

In this post under DateTime, I will show how to convert an instance of “Date” class to “Instant” instance. Below is the code to that will do the conversion. Date date = new Date(); Instant instant = date.toInstant(); As shown in the above code snippet, first we create a “Date” instance and store in “date”…… Continue reading Converting Date instance to Instant instance

Converting Instant instance to Date instance

In this post under DateTime, I will show how to convert an instance of “Instant” class to “Date” instance. Below is the code to that will do the conversion. Instant instant = Instant.now(); Date date = Date.from(instant); “now” static method of “Instant” class will return an “Instant” instance representing the current date time. Then we…… Continue reading Converting Instant instance to Date instance

Serializing and De-Serializing Date object to and from a custom pattern

In this post under Java, I will show with example how to serialize and de-serialize Date object using a custom pattern. In the previous post, we used “SimpleDateFormat” class to serialize and de-serialize Date object using a pattern obtained based on system default locale. This pattern was figured out by Java and was not provided…… Continue reading Serializing and De-Serializing Date object to and from a custom pattern

Serializing and De-Serializing Date object to and from pattern

In this post, I will show with example how to serialize and deserialize Date object. Java provides “SimpleDateFormat” class to serialize and deserialize Date objects. Below is an example Main class 1 package datetime; 2 3 import java.text.ParseException; 4 import java.text.SimpleDateFormat; 5 import java.util.Date; 6 7 public class Example1 { 8 public static void main(String[]…… Continue reading Serializing and De-Serializing Date object to and from pattern