Java Hour Format formatDate(String pattern, Date date)

Here you can find the source of formatDate(String pattern, Date date)

Description

Formats a java.util.Date object into a string according to a specified pattern.

License

Open Source License

Parameter

Parameter Description
pattern The SimpleDateFormat pattern to use (e.g. "yyyyMMddHHmmss").
date The java.util.Date object to format.

Return

The formatted date string.

Declaration

public static String formatDate(String pattern, Date date) 

Method Source Code

//package com.java2s;
/*//ww  w  . ja v  a 2  s  . c  o m
 * Copyright (c) Mirth Corporation. All rights reserved.
 * 
 * http://www.mirthcorp.com
 * 
 * The software in this package is published under the terms of the MPL license a copy of which has
 * been included with this distribution in the LICENSE.txt file.
 */

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

public class Main {
    /**
     * Formats a java.util.Date object into a string according to a specified pattern.
     * 
     * @param pattern
     *            The SimpleDateFormat pattern to use (e.g. "yyyyMMddHHmmss").
     * @param date
     *            The java.util.Date object to format.
     * @return The formatted date string.
     */
    public static String formatDate(String pattern, Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        return formatter.format(date);
    }
}

Related

  1. formatDate(String date)
  2. formatDate(String date)
  3. formatDate(String dateTimeString)
  4. formatDate(String format)
  5. formatDate(String inputStr)
  6. formatDate2DateTimeStr()
  7. formatDate2DateTimeStr()
  8. formatDate3DateTimeStr(Date date)
  9. formatDateAddHMS(String strDate)