Java SQL Time Create getTime(long time, boolean allowNull)

Here you can find the source of getTime(long time, boolean allowNull)

Description

Gets the database format for a time field.

License

Open Source License

Parameter

Parameter Description
allowNull When true , if the time is -1 , returns null

Declaration

public static String getTime(long time, boolean allowNull) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w .ja v a 2s. co  m*/
 * aocode-public - Reusable Java library of general tools with minimal external dependencies.
 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013, 2016, 2018  AO Industries, Inc.
 *     support@aoindustries.com
 *     7262 Bull Pen Cir
 *     Mobile, AL 36695
 *
 * This file is part of aocode-public.
 *
 * aocode-public is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aocode-public 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with aocode-public.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.sql.Timestamp;

public class Main {
    /**
     * Gets the database format for a time field.
     *
     * @param  allowNull   When {@code true}, if the time is {@code -1}, returns {@code null}
     */
    public static String getTime(long time, boolean allowNull) {
        return allowNull && time == -1 ? null : new Timestamp(time).toString().substring(11, 19); // TODO: Not y10k compliant
    }

    /**
     * Gets the database format for a time field.
     *
     * @param time  if the time is {@code -1}, returns {@code null}
     *
     * @see  #getTime(long, boolean)
     *
     * @deprecated   Please use {@link #getTime(long, boolean)} to specify if {@code null} is allowed
     */
    @Deprecated
    public static String getTime(long time) {
        return getTime(time, true);
    }
}

Related

  1. getTime(GregorianCalendar cal)
  2. getTime(java.util.Date date)
  3. getTime(long time)
  4. getTime(long time)
  5. getTime(long time)
  6. getTime(Map map, String attr)
  7. getTime(Object value)
  8. getTime(Object value, int columnType)
  9. getTime(ResultSet resultSet, String columnName)