Here you can find the source of getYYYYMMDD(int y, int m, int d)
public static String getYYYYMMDD(int y, int m, int d)
//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()); } }