zoukankan      html  css  js  c++  java
  • java如何遍历当月所有的日期?

    转自:https://zhidao.baidu.com/question/360215274.html

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

    public class Test {

    public static void main(String[] args) {

    List<Date> list = getAllTheDateOftheMonth(new Date());

    for(Date date: list){
    System.out.println(date.toString());
    }

    }

    private static List<Date> getAllTheDateOftheMonth(Date date) {
    List<Date> list = new ArrayList<Date>();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.DATE, 1);

    int month = cal.get(Calendar.MONTH);
    while(cal.get(Calendar.MONTH) == month){
    list.add(cal.getTime());
    cal.add(Calendar.DATE, 1);
    }
    return list;
    }

    }
  • 相关阅读:
    SWT DragSource 和 DropTarget 托拉拽
    Java的反射机制
    1. 算法导论
    SWT对于监听Tab键的理解
    SWT基础
    socket
    TCP/IP
    RPC(远程过程调用协议)
    Jython基本知识
    #与##
  • 原文地址:https://www.cnblogs.com/YuyuanNo1/p/8510588.html
Copyright © 2011-2022 走看看