Java Year Format getYYYYMMDD(Date date)

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

Description

get YYYYMMDD

License

Open Source License

Declaration

public static String getYYYYMMDD(Date date) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Boeing.//  w  w  w.j ava 2s  . c  o  m
 * 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
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public final static String YYYYMMDD = "yyyy/MM/dd";

    public static String getYYYYMMDD() {
        return getYYYYMMDD(new Date());
    }

    public static String getYYYYMMDD(Date date) {
        return get(date, YYYYMMDD);
    }

    public static String get(Date date) {
        if (date == null) {
            return "";
        }
        return DateFormat.getDateInstance().format(date);
    }

    public static String get(Date date, String pattern) {
        return get(date, new SimpleDateFormat(pattern));
    }

    public static String get(Date date, DateFormat dateFormat) {
        if (date == null) {
            return "";
        }
        String result = dateFormat.format(date);
        return result;
    }
}

Related

  1. getyyyy_MM_dd(Date date)
  2. getyyyy_MM_dd2(String date)
  3. getYYYYMM()
  4. getYYYYMM(final Date date, final String separator)
  5. getYYYYMMDD(Date date)
  6. getYYYYMMDD(int y, int m, int d)
  7. getYyyyMMddDate(String s)
  8. getyyyyMMddDateStr(Date date)
  9. getYYYYMMDDFormat()