Java Hour Format formatDateTime(final Date dat)

Here you can find the source of formatDateTime(final Date dat)

Description

Format Date accoring to Patter of 'YYYY-MM-DD 24H:mm' and Locale of US

License

Open Source License

Parameter

Parameter Description
dat Date to formate

Return

Formatted Date

Declaration

public static String formatDateTime(final Date dat) 

Method Source Code


//package com.java2s;
/*// w  w  w .ja  v a 2  s  . c om
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). 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 Wincor Nixdorf.
 */

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

public class Main {
    public static final String SHORT_DATE_FORMAT = "yyyy-MM-dd";

    /**
     * Format Date accoring to Patter of 'YYYY-MM-DD 24H:mm' and Locale of US
     *
     * @param dat Date to formate
     * @return Formatted Date
     */
    public static String formatDateTime(final Date dat) {
        return formatDate(dat, "yyyy-MM-dd HH:mm", Locale.US);

    }

    /**
     * Format Date accoring to Patter of 'YYYY-MM-DD' and Locale of US
     *
     * @param dat Date to formate
     * @return Formatted Date
     */
    public static String formatDate(final Date dat) {
        return formatDate(dat, SHORT_DATE_FORMAT, Locale.US);
    }

    /**
     * Formate Date according to Patter and Locale of US
     *
     * @param dat     Date to format
     * @param pattern Pattern of Date to format
     * @return Formatted Date
     */
    public static String formatDate(final Date dat, final String pattern) {
        return formatDate(dat, pattern, Locale.US);

    }

    /**
     * Formate Date accoring to Pattern and Locale
     *
     * @param dat     Date to formate
     * @param pattern Pattern of Date to Format
     * @param loc     Locale of Date to format
     * @return Formatted Date
     */
    public static String formatDate(final Date dat, final String pattern, final Locale loc) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern, loc);
        if (dat != null) {
            return sdf.format(dat);
        } else {
            return "";
        }
    }
}

Related

  1. formatDatetime(Date date)
  2. formatDateTime(Date date)
  3. formatDateTime(Date dateTime)
  4. formatDateTime(Date myDate)
  5. formatDateTime(final Calendar cal)
  6. formatDateTime(final Date date)
  7. formatDateTime(java.util.Date d)
  8. formatDateTime(java.util.Date date)
  9. formatDateTime(java.util.Date date)