Java SQL Date calcLastMonth(String begin, String end, String now, GregorianCalendar calendar)

Here you can find the source of calcLastMonth(String begin, String end, String now, GregorianCalendar calendar)

Description

calc Last Month

License

Apache License

Declaration

public static void calcLastMonth(String begin, String end, String now, GregorianCalendar calendar) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

public class Main {
    public static void calcLastMonth(String begin, String end, String now, GregorianCalendar calendar) {

        calendar.set(calendar.get(GregorianCalendar.YEAR), calendar.get(GregorianCalendar.MONTH), 1);
        calendar.add(GregorianCalendar.DATE, -1);
        //end = new  java.sql.Date(calendar.getTime().getTime()).toString();

        int month = calendar.get(GregorianCalendar.MONTH) - 1;
        int d = new Date().getDate();
        begin = calendar.get(GregorianCalendar.YEAR) + "-" + month + "-" + d;

        System.out.println(" begin: " + begin);
        //System.out.println( " end: " + end);
        System.out.println(" ---------------------- ");
    }//ww w  .  ja v a  2 s .  c om

    public static List<Date> getdate(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int today = c.get(Calendar.DAY_OF_WEEK);
        List<Date> list = new ArrayList<Date>();

        for (int i = 1; i < today - 1; i++) {
            c.add(Calendar.DAY_OF_WEEK, -today + i + 1);
            c.getTime();
            list.add(c.getTime());
            c.setTime(date);
        }
        list.add(date);
        for (int i = 1; i < 7 - today + 2; i++) {
            c.add(Calendar.DAY_OF_WEEK, i);
            c.getTime();
            list.add(c.getTime());
            c.setTime(date);
        }
        return list;
    }
}

Related

  1. calcThisMonth(String begin, String end, String now, GregorianCalendar calendar)
  2. canConvert(Class clz)
  3. convert(Class propertyType, Object value, String propertyName)
  4. convert(Object o)