自用工具类

自用工具类方法

时间工具类

// An highlighted block
  /**
     * 返回日时分秒
     *
     * @param second 秒数
     * @return
     */
    private String secondToTime(long second) {
        long days = second / 86400;//转换天数
        second = second % 86400;//剩余秒数
        long hours = second / 3600;//转换小时数
        second = second % 3600;//剩余秒数
        long minutes = second / 60;//转换分钟
        second = second % 60;//剩余秒数
        if (0 < days) {
            return days + "天," + hours + "小时," + minutes + "分," + second + "秒";
        } else {
            return hours + "小时," + minutes + "分," + second + "秒";
        }

    }
返回示例: 214,12小时,0,0
 /**
     * 根据cron表达式算出两次执行的时间
     * @param cronExpression
     * @param numTimes
     * @return
     */
    public static List<String> getNextExecTime(String cronExpression, Integer numTimes) {
        List<String> list = new ArrayList<>();
        CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
        try {
            cronTriggerImpl.setCronExpression(cronExpression);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        // 这个是重点,一行代码搞定
        List<Date> dates = TriggerUtils.computeFireTimes(cronTriggerImpl, null, numTimes);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (Date date : dates) {
            list.add(dateFormat.format(date));
        }
        return list;
    }

分页工具类

public class MyPagebale<T> {
	private List<T> records;
	private int size;
	private int current;
	private  int pages;
	private int total;//总数
	public MyPagebale(int size, int current, List<T> records, int totals){
		this.size=size;
		this.current=current;
		this.total=totals;
		this.pages=total%size==0?total/size:total/size+1;
		this.records=records;
	}
		public MyPagebale(int size,int current,List<T> records,int total,Integer D){
		this.size=size;
		this.current=current;
		this.total=total;
		this.pages=total%size==0?total/size:total/size+1;
		this.records=records==null||records.size()==0?new ArrayList<T>() :
			records.subList((current-1)*size,(current-1)*size+size>records.size()?
			records.size():((current-1)*size+size));
	}
	public List<T> getRecords() {
		return records;
	}

	public void setRecords(List<T> records) {
		this.records = records;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public int getCurrent() {
		return current;
	}

	public void setCurrent(int current) {
		this.current = current;
	}

	public int getPages() {
		return pages;
	}

	public void setPages(int pages) {
		this.pages = pages;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值