java.util.Date as Sql Date - Java java.sql

Java examples for java.sql:Date

Description

java.util.Date as Sql Date

Demo Code


//package com.java2s;

import java.time.LocalDate;

import java.time.ZoneId;
import java.util.Date;

public class Main {
    public static java.sql.Date asSqlDate(java.util.Date date) {
        return new java.sql.Date(date.getTime());
    }// ww  w  .jav a  2  s.  c  o m

    public static java.sql.Date asSqlDate(LocalDate localDate) {
        return new java.sql.Date(Date.from(
                localDate.atStartOfDay().atZone(ZoneId.systemDefault())
                        .toInstant()).getTime());
    }
}

Related Tutorials