Java SQL Time unformattedFromTime(java.sql.Time t)

Here you can find the source of unformattedFromTime(java.sql.Time t)

Description

Convert from a Time to an unlocalized string with the format hhmmss.

License

Open Source License

Parameter

Parameter Description
t A <i>Time</i>.

Return

The string.

Declaration

public static String unformattedFromTime(java.sql.Time t) 

Method Source Code

//package com.java2s;
/*/*from w  w  w . j  a  v  a 2 s.co  m*/
 * Copyright (C) 2015 Miquel Sas
 *
 * 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/>.
 */

import java.text.SimpleDateFormat;

public class Main {
    /**
     * Convert from a <i>Time</i> to an unlocalized string with the format <i>hhmmss</i>.
     * 
     * @return The string.
     * @param t A <i>Time</i>.
     */
    public static String unformattedFromTime(java.sql.Time t) {
        return unformattedFromTime(t, false);
    }

    /**
     * Convert from a <i>Time</i> to an unlocalized string with the format <i>hhmmss</i> or <i>hhmmssnnn</i>.
     * 
     * @return The string.
     * @param time A <i>Time</i>.
     * @param millis A <i>boolean</i> to include milliseconds.
     */
    public static String unformattedFromTime(java.sql.Time time, boolean millis) {
        if (time == null) {
            return "";
        }
        StringBuilder pattern = new StringBuilder();
        pattern.append("HHmmss");
        if (millis) {
            pattern.append("SSS");
        }
        SimpleDateFormat df = new SimpleDateFormat(pattern.toString());
        return df.format(time);
    }
}

Related

  1. todayBeginTime()
  2. toGMTTime(long local)
  3. toMySQLDate(LocalDateTime dateTime)
  4. toPOSIXTime(String timeString)
  5. truncateTimePartOfDate(Date date)