Java SQL Date Create getLastDateOfQuarter()

Here you can find the source of getLastDateOfQuarter()

Description

get Last Date Of Quarter

License

Open Source License

Declaration

public static String getLastDateOfQuarter() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.Timestamp;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

    public static Timestamp getLastDateOfQuarter(int year, int quarter) {
        //        checkYearAndQuarter(year, quarter);
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, 3 * quarter);
        calendar.set(Calendar.DATE, 1);
        calendar.add(Calendar.DATE, -1);
        return new Timestamp(calendar.getTime().getTime());
    }//ww w  . ja  va  2s .  c  om

    public static String getLastDateOfQuarter() {
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int quater = (month + 2) / 3;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        return formatter.format(getLastDateOfQuarter(year, quater));
    }

    public static Timestamp format(Timestamp time) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = sdf.format(time);
        date = date.substring(0, 10) + " 00:00:00";
        time = new Timestamp(sdf.parse(date).getTime());
        return time;
    }
}

Related

  1. getDayByMonthSeed(Date date, int monthSeed)
  2. getDayByWeekString(Date date, String weekString)
  3. getDays(Date from, Date to)
  4. getDaysLater(Date date, int days)
  5. getDayStart(Date stamp)
  6. getLastDay(Date date)
  7. getLastDay(Date dt)
  8. getLastDay(java.util.Date dt)
  9. getLastDayofMonth(Date date1)