Java Year Format getYYYYMMDD(int y, int m, int d)

Here you can find the source of getYYYYMMDD(int y, int m, int d)

Description

get YYYYMMDD

License

Open Source License

Declaration

public static String getYYYYMMDD(int y, int m, int d) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * @(#)DateFormatUtil.java 2012-3-12/* w w  w . j  a v a  2 s.  c  om*/
 *
 * Copyright 2012 Neusoft Group Ltd. All rights reserved.
 * Neusoft PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *******************************************************************************/

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {

    public static String getYYYYMMDD() {
        Calendar cal = Calendar.getInstance();
        String dateStr = "" + cal.get(Calendar.YEAR);

        int month = cal.get(Calendar.MONTH) + 1;
        if (month < 10) {
            dateStr = dateStr + "0" + month;
        } else {
            dateStr = dateStr + "" + month;
        }
        int day = cal.get(Calendar.DAY_OF_MONTH);
        if (day < 10) {
            dateStr = dateStr + "0" + day;
        } else {
            dateStr = dateStr + "" + day;
        }

        return dateStr;
    }

    public static String getYYYYMMDD(int y, int m, int d) {
        Calendar cal = Calendar.getInstance();

        cal.add(Calendar.YEAR, y);
        cal.add(Calendar.MONTH, m);
        cal.add(Calendar.DATE, d);

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        return format.format(cal.getTime());
    }
}

Related

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