Java Locale Format format(Date date)

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

Description

Formats a Date based on the default Locale If teh Date is null returns an empty String

License

Open Source License

Parameter

Parameter Description
date the Date to format

Return

the formatted Date as a String

Declaration

public static String format(Date date) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *  Copyright (c) 2000, 2010 IBM Corporation and others.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 * //w w  w  . j a  v  a  2 s . c om
 *  Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

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

import java.util.Locale;

public class Main {
    private static final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
            DateFormat.DEFAULT, Locale.getDefault());

    /**
     * Formats a Date based on the default Locale 
     * If teh Date is <code>null</code> returns an empty String
     * 
     * @param date the Date to format
     * @return the formatted Date as a String
     * @since 2.0
     */
    public static String format(Date date) {
        if (date == null)
            return ""; //$NON-NLS-1$
        return dateFormat.format(date);
    }
}

Related

  1. format(BigInteger amount)
  2. format(Date d, Locale locale)
  3. format(Date d, String format)
  4. format(Date date)
  5. format(Date date, String format)
  6. format(Date date, String format, Locale locale)
  7. format(Date date, String parttern)
  8. format(Date date, String pattern)