Java Data Type How to - Convert LocalDateTime to java.sql.Timestamp


We would like to know how to convert LocalDateTime to java.sql.Timestamp.


import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
//from w w w. j  a  va  2 s .c o  m
public class Main {

  public static void main(String[] args) {

  public static Timestamp timeZoneAdjustedDate(LocalDateTime due) {
    return Timestamp.from(due.toInstant(ZoneOffset.ofHours(0)));


The code above generates the following result.