Java 8 – Convert LocalDate to Instant

Below Java8 example shows you how to convert LocalDate to Instant.

Convert LocalDate to Instant

package com.sneppets.solution;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;

public class LocalDateToInstant {
	
	public static void main (String[] args) {
		
		LocalDate localDate = LocalDate.now();
		System.out.println("LocalDate now() : " + localDate);
		
		//convert localdate to Instant
		Instant instant = localDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
		System.out.println("Instant : " + instant);
	}
	
}

Output

LocalDate now() : 2019-11-28
Instant : 2019-11-27T18:30:00Z

Further Learning

References

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments