Java Month Get getThisMonth()

Here you can find the source of getThisMonth()

Description

get This Month

License

Open Source License

Declaration

public static List<String> getThisMonth() 

Method Source Code

//package com.java2s;
/**/* w w  w  .  j a  v  a 2s .  c  o m*/
 * Copyright (c)2010-2011 Enterprise Website Content Management System(EWCMS), All rights reserved.
 * EWCMS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * http://www.ewcms.com
 */

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Main {
    private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";

    public static List<String> getThisMonth() {
        return getThisMonth(DEFAULT_DATE_FORMAT);
    }

    public static List<String> getThisMonth(String format) {
        List<String> list = new ArrayList<String>();
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
            Date firstDate = calendar.getTime();

            SimpleDateFormat simple = new SimpleDateFormat(format);
            Date current = new Date(Calendar.getInstance().getTime().getTime());

            Long mid = current.getTime() - firstDate.getTime() + 1;
            int day = (int) (mid / (1000 * 60 * 60 * 24));

            calendar.setTime(firstDate);
            list.add(simple.format(firstDate.getTime()));
            for (int i = 0; i < day; i++) {
                calendar.add(Calendar.DATE, 1);
                list.add(simple.format(calendar.getTime()));
            }
        } catch (Exception e) {

        }
        return list;
    }
}

Related

  1. getSpecficMonthStart(Date date, int amount)
  2. getStartDateOfMonth(String yyyymm)
  3. getStrOfNextMonth(String dateStr)
  4. getStrThisMonth()
  5. getThisMonth()
  6. getThisMonth()
  7. getThisMonthAndCycle()
  8. getThisMonthDate()
  9. getThisMonthLastDate()