Java SQL LocalDate toJDBC(LocalDate fecha)

Here you can find the source of toJDBC(LocalDate fecha)

Description

Convierte la fecha en el formato de Joda-Time al equivalente en el formato de JDBC java.sql.Date

License

Open Source License

Parameter

Parameter Description
fecha la fecha en formato Joda-Time

Return

la misma fecha en formato JDBC

Declaration

public static Date toJDBC(LocalDate fecha) 

Method Source Code

//package com.java2s;
/**/*from  www .j  av  a  2 s . co m*/
 * Copyright 2007,2008,2012 Sergi Baila (sargue@gmail.com)
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If
 * not, see <http://www.gnu.org/licenses/>.
 * 
 * M?todos auxiliares para la libreria Joda-Time.
 * 
 * <pre>
 * Changelog:
 *  23/08/2007 - primera versi?n base
 *  05/09/2007 - formateadores globales (son thread-safe)
 *  19/03/2008 - nuevos m?todos from*, correcci?n bug nulls m?todos to*
 *  03/01/2012 - adaptado para publicar
 * </pre>
 */

import org.joda.time.*;

import java.sql.*;

public class Main {
    /**
     * Convierte la fecha en el formato de Joda-Time al equivalente en el formato de JDBC
     * java.sql.Date
     * 
     * @param fecha la fecha en formato Joda-Time
     * @return la misma fecha en formato JDBC
     */
    public static Date toJDBC(LocalDate fecha) {
        return fecha == null ? null : new Date(fecha.toDateMidnight().getMillis());
    }

    /**
     * Convierte la hora en el formato de Joda-Time al equivalente en el formato de de JDBC
     * java.sql.Time
     * 
     * @param hora la fecha en formato Joda-Time
     * @return la misma hora en formato JDBC
     */
    public static Time toJDBC(LocalTime hora) {
        return hora == null ? null : new Time(hora.toDateTimeToday().getMillis());
    }

    /**
     * Convierte la fecha y hora en el formato de Joda-Time al equivalente en el formato de JDBC
     * java.sql.Timestamp
     * 
     * @param dt la fecha en formato Joda-Time
     * @return la misma fecha en formato JDBC
     */
    public static Timestamp toJDBC(ReadableInstant dt) {
        return dt == null ? null : new Timestamp(dt.getMillis());
    }
}

Related

  1. toDate(LocalDate localDate)
  2. toDate(LocalDate localDate)
  3. toDate(LocalDate localDate)
  4. toInstant(Date date)
  5. toJavaDate(DateMidnight dm)
  6. toLocalDate(Date date)
  7. toLocalDate(Date date)
  8. toLocalDate(final Date d)
  9. toLocalDate(java.sql.Date date)