Java Timestamp Format formatTime(Timestamp time, boolean onlyTime)

Here you can find the source of formatTime(Timestamp time, boolean onlyTime)

Description

This method converts a JDBC format date into a String

License

Open Source License

Parameter

Parameter Description
date JDBC format time
onlyTime controls whether date will be included or not

Return

date in "dd-MMM-yyyy-HH:mm" or "HH:mm" format

Declaration

public static String formatTime(Timestamp time, boolean onlyTime) 

Method Source Code

//package com.java2s;
/*//  ww  w .  jav a 2  s. c o  m
 * @(#)ConversionUtils.java
 *
 * Copyright by ObjectFrontier, Inc.,
 * 12225 Broadleaf Lane, Alpharetta, GA 30005, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of ObjectFrontier, Inc. You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of
 * the license agreement you entered into with ObjectFrontier.
 */

import java.sql.Timestamp;

import java.text.SimpleDateFormat;

public class Main {
    protected static SimpleDateFormat userTimeFmt = new SimpleDateFormat("dd-MM-yyyy'-'HH:mm");
    protected static SimpleDateFormat userTimeOnlyFmt = new SimpleDateFormat("HH:mm");

    /**
     * This method converts a JDBC format date into a <code>String</code>
     *
     * @param   date JDBC format time
     * @param   onlyTime controls whether date will be included or not
     *
     * @return  date in "dd-MMM-yyyy-HH:mm" or "HH:mm" format
     */
    public static String formatTime(Timestamp time, boolean onlyTime) {

        if (time == null)
            return null;

        return (onlyTime) ? userTimeOnlyFmt.format(time) : userTimeFmt.format(time);
    }
}

Related

  1. formatString(Timestamp da)
  2. formatStringToTimeStamp(String s)
  3. formattedDateTime(long timestamp)
  4. formatTime(Date aTs_Datetime)
  5. formatTime(Date date)
  6. formatTime(Timestamp ts, Locale locale)
  7. formatTimeFromTimestamp(long ts, String fmt)
  8. formatTimestamp(Date date)
  9. formatTimestamp(Date timestamp)