package com.xzz.jihepaixu;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.ToString;
import java.util.Date;
import java.io.Serializable;
/**
* @ClassName JiHe
* @Date 20210918
* @Author lcl-xiezezhong
* @Version 1.0
*/
@Data
@ToString
public class JiHe implements Serializable, Comparable<JiHe>{
@JsonIgnore
private Date endTime;
@Override
public int compareTo(JiHe o) {
return endTime.compareTo(o.getEndTime());
}
}
package com.xzz.jihepaixu;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
/**
* @ClassName JiHe
* @Date 20210918
* @Author lcl-xiezezhong
* @Version 1.0
*/
public class JiHeTest{
public static void main(String[] args) throws ParseException {
List<JiHe> arrayList = new ArrayList<>();
JiHe jiHe = new JiHe();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
Date parse = simpleDateFormat.parse("20210930000000");
jiHe.setEndTime(parse);
JiHe jiHe1 = new JiHe();
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyyMMddHHmmss");
Date parse1 = simpleDateFormat2.parse("20211231235959");
jiHe1.setEndTime(parse1);
arrayList.add(jiHe);
arrayList.add(jiHe1);
//默认排序 从大往小排序
Collections.sort(arrayList);
System.out.println(arrayList);
}
}