returns the sql date - Java java.sql

Java examples for java.sql:Date

Description

returns the sql date

Demo Code


//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**//  ww  w . ja va2s .  c om
     * this method returns the sql date
     *
     * @param timestampKey
     *            given timestamp
     * @return java.sql.Date return the sql date
     */
    public static java.sql.Date getSqlDate(final long timestampKey) {
        Date date = new Date(timestampKey);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return new java.sql.Date(calendar.getTimeInMillis());
    }
}

Related Tutorials