Here you can find the source of getDate()
public static Date getDate()
//package com.java2s; /*/* w ww. j av a 2 s. co m*/ * Copyright 2012-2014 sammyun.com.cn. All rights reserved. * Support: http://www.sammyun.com.cn * License: http://www.sammyun.com.cn/license */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static Date getDate() { return new Date(); } public static Date getDate(int datas) { GregorianCalendar calendar = new GregorianCalendar(); calendar.add(GregorianCalendar.DATE, datas); String begin = new java.sql.Date(calendar.getTime().getTime()).toString(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date beginDate = null; try { beginDate = sdf.parse(begin); } catch (ParseException e) { e.printStackTrace(); } return beginDate; } public static Date getDate(Date beginDate, int datas) { Calendar beginCal = Calendar.getInstance(); beginCal.setTime(beginDate); GregorianCalendar calendar = new GregorianCalendar(beginCal.get(Calendar.YEAR), beginCal.get(Calendar.MONTH), beginCal.get(Calendar.DATE)); calendar.add(GregorianCalendar.DATE, datas); String begin = new java.sql.Date(calendar.getTime().getTime()).toString(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date endDate = null; try { endDate = sdf.parse(begin); } catch (ParseException e) { e.printStackTrace(); } return endDate; } }