Java Timestamp Format formatDate(java.util.Date date)

Here you can find the source of formatDate(java.util.Date date)

Description

This method converts a JDBC format date into a String

License

Open Source License

Parameter

Parameter Description
date JDBC format date

Return

date in "dd-MMM-yyyy" format

Declaration

public static String formatDate(java.util.Date date) 

Method Source Code

//package com.java2s;
/*//from  www  .j  av a  2  s .co  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 userDateFmt = new SimpleDateFormat("dd-MM-yyyy");

    /**
     * This method converts a JDBC format date into a <code>String</code>
     *
     * @param   date JDBC format date
     *
     * @return  date in "dd-MMM-yyyy" format
     */
    public static String formatDate(java.util.Date date) {

        if (date == null)
            return null;

        return userDateFmt.format(date);
    }

    /**
     * This method converts a JDBC format date into a <code>String</code>
     *
     * @param   date JDBC format date
     * @param   dateFormat 
     *
     * @return  date in user defined format
     */
    public static String formatDate(java.util.Date date, String simpleDateFormat) {

        if (date == null)
            return null;

        return new SimpleDateFormat(simpleDateFormat).format(date);
    }

    /**
     * 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" format
     */
    public static String formatDate(Timestamp time) {

        if (time == null)
            return null;

        return userDateFmt.format(time);
    }
}

Related

  1. formatDataTime(Timestamp intime)
  2. formatDate(Date date, String pattern)
  3. formatDate(Date date, String pattern)
  4. formatDate(java.sql.Timestamp timestamp)
  5. formatDate(java.util.Date d)
  6. formatDate(Timestamp date)
  7. formatDate(Timestamp time)
  8. formatDate(Timestamp time, String pattern)
  9. formatDate(Timestamp timestamp)