一天划分阶段

package shop.service;

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

public class DateUtils {
    //将一天等分为三个阶段
    public List<Integer> getDayNode(int phase){
        ArrayList<Integer> nodes = new ArrayList<>();
        int i = 24/phase;
        for (int j = 0; j < phase; j++) {
            nodes.add(i*j);
        }
        return nodes;
    }
    // 获取时间节点对象
    public List<Date> getDayNodeDate(Date date){
        List<Integer> dayNode = getDayNode();
        ArrayList<Date> dayNodeDateList = new ArrayList<>();
        for (int i = 0; i < dayNode.size(); i++) {
            Date dateNode = new Date(date.getYear(),date.getMonth(),date.getDate(),dayNode.get(i),0,0);
            dayNodeDateList.add(dateNode);
        }
        return dayNodeDateList;
    }
}
Last modification:September 15th, 2020 at 07:01 pm