Java Timestamp Create toSqlTimeStamp(Date d)

Here you can find the source of toSqlTimeStamp(Date d)

Description

to Sql Time Stamp

License

Apache License

Declaration

public static Timestamp toSqlTimeStamp(Date d) 

Method Source Code

//package com.java2s;
/*/*from www . ja v  a2 s  .c  o  m*/
 * JEF - Copyright 2009-2010 Jiyi (mr.jiyi@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.sql.Timestamp;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

import java.util.Date;

public class Main {

    public static Timestamp toSqlTimeStamp(Date d) {
        if (d == null)
            return null;
        return new java.sql.Timestamp(d.getTime());
    }

    /**
     * Converts LocalDateTime to Timestamp (null safety)
     * @param time LocalDateTime
     * @return Timestamp
     */
    public static java.sql.Timestamp toSqlTimeStamp(LocalDateTime time) {
        return time == null ? null : java.sql.Timestamp.valueOf(time);
    }

    /**
     * Converts instant to Timestamp (null safety)
     * @param instant Instant
     * @return java.sql.Timestamp
     */
    public static java.sql.Timestamp toSqlTimeStamp(Instant instant) {
        return instant == null ? null : java.sql.Timestamp.from(instant);
    }

    /**
     * Converts LocalTime to Timestamp (null safety)
     * @param localTime LocalTime
     * @return Timestamp
     */
    public static Timestamp toSqlTimeStamp(LocalTime localTime) {
        return localTime == null ? null : java.sql.Timestamp.valueOf(LocalDateTime.of(LocalDate.now(), localTime));
    }

    public static Date now() {
        return new Date();
    }
}

Related

  1. timestampStringToUnixDate(String s)
  2. toOracleTimestamp(String stringDate, int intFlag)
  3. toSQLTime(Instant timestamp)
  4. toSqlTime(Timestamp timestamp)
  5. toSqlTimestamp(Date d)
  6. toSQLTimestamp(Date date)
  7. toSQLTimestamp(DateTime dt)
  8. toSqlTimestamp(java.util.Date date)
  9. toSQLTimestamp(Object object, Object oDefault)