Java Hour Format format(final Date date)

Here you can find the source of format(final Date date)

Description

Formats a Date according to the default date format.

License

Open Source License

Parameter

Parameter Description
date The date to format.

Return

The formatted date.

Declaration

public static String format(final Date date) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2010-2016 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
 *
 * This file is part of SITools2.//from   w ww .  jav  a2  s .co m
 *
 * SITools2 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * SITools2 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

import java.util.Date;

public class Main {
    /**
     * Default date format for date exchange between the server and the client in all the Sitools2 application
     */
    public static final String SITOOLS_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS";

    /**
     * Formats a Date according to the default date format.
     *
     * @param date
     *          The date to format.
     * @return The formatted date.
     */
    public static String format(final Date date) {
        return format(date, SITOOLS_DATE_FORMAT);
    }

    /**
     * Formats a Date according to the first format in the array.
     *
     * @param date
     *          The date to format.
     * @param format
     *          The date format to use.
     * @return The formatted date.
     */
    public static String format(final Date date, final String format) {
        if (date == null) {
            throw new IllegalArgumentException("Date is null");
        }
        java.text.DateFormat formatter = null;
        formatter = new java.text.SimpleDateFormat(format, java.util.Locale.ROOT);

        return formatter.format(date);
    }
}

Related

  1. format(Date dt)
  2. format(Date self, String format, TimeZone tz)
  3. format(Date time, String fmt)
  4. format(double number, int decimalPlace)
  5. format(final Date date)
  6. format(final Date date)
  7. format(int level, String message, String source, boolean verbose)
  8. format(java.util.Date date, String format)
  9. format(List list, int scale)