Java SQL Date Get getDate()

Here you can find the source of getDate()

Description

get Date

License

Open Source License

Declaration

public static Date getDate() 

Method Source Code

//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;
    }
}

Related

  1. getDate()
  2. getDate()
  3. getDate()
  4. getDate()
  5. getDate()
  6. getDate(Calendar pCal)
  7. getDate(Date date)
  8. getDate(Date value)
  9. getDate(final int year, final int month, final int day)