Here you can find the source of formatTime(Timestamp time, boolean onlyTime)
String
Parameter | Description |
---|---|
date | JDBC format time |
onlyTime | controls whether date will be included or not |
public static String formatTime(Timestamp time, boolean onlyTime)
//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); } }