Java Hour Format format(Date dt)

Here you can find the source of format(Date dt)

Description

Format the date using the default date format.

License

Apache License

Parameter

Parameter Description
dt - Date

Exception

Parameter Description
Exception an exception

Declaration

public static final String format(Date dt) throws Exception 

Method Source Code

//package com.java2s;
/**// ww  w .j  a  v  a2s.  co m
 * Copyright 2012 Subho Ghosh (subho dot ghosh at outlook dot com)
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *        http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static final String _DEFAULT_DATE_FORMAT_ = "MM-dd-yyyy HH:mm:ss";

    /**
     * Format the date using the default date format.
     * 
     * @param dt
     *            - Date
     * @return
     * @throws Exception
     */
    public static final String format(Date dt) throws Exception {
        DateFormat formatter = new SimpleDateFormat(_DEFAULT_DATE_FORMAT_);
        return formatter.format(dt);
    }

    /**
     * Format the date using the specified date format.
     * 
     * @param dt
     *            - Date
     * @param format
     *            - Date Format
     * @return
     * @throws Exception
     */
    public static final String format(Date dt, String format) throws Exception {
        DateFormat formatter = new SimpleDateFormat(format);
        return formatter.format(dt);
    }
}

Related

  1. format(Date date, String format)
  2. format(Date date, String format)
  3. format(Date date, String pattern)
  4. format(Date date, String ptrn)
  5. format(Date dateTime)
  6. format(Date self, String format, TimeZone tz)
  7. format(Date time, String fmt)
  8. format(double number, int decimalPlace)
  9. format(final Date date)