Java Date Format formatDate(Date date)

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

Description

format Date

License

Open Source License

Return

Localized date value in format yyyy-MM-dd

Declaration

public static String formatDate(Date date) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * 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
 *******************************************************************************/

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

public class Main {
    private static SimpleDateFormat dateDF = // getDateShortFormat
            new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
    private static String NOT_DEFINED_DATE = "-";

    /**/*w  w  w.  j  a va  2s. co  m*/
     * @return Localized date value in format yyyy-MM-dd
     */
    public static String formatDate(Date date) {
        if (date == null) {
            return NOT_DEFINED_DATE;
        }
        return dateDF.format(date.getTime());
    }

    public static String getTime(Date time, int format, Locale locale) {
        return SimpleDateFormat.getTimeInstance(format, locale).format(time);
    }
}

Related

  1. formatDate(Date date)
  2. formatDate(Date date)
  3. formatDate(Date date)
  4. formatDate(Date date)
  5. formatDate(Date date)
  6. formatDate(Date date)
  7. formatDate(Date date)
  8. formatDate(Date date)
  9. formatDate(Date date)