zoukankan      html  css  js  c++  java
  • Java先比较日期再比较时间

    package com.bihang.seaya;
    
    import lombok.Data;
    
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.*;
    
    /**
     * Created By bihang
     * 2019/1/15 14:09
     */
    public class Manitest {
        public static void main(String[] args) throws ParseException {
            List<TestU> testUS = new ArrayList<>();
            testUS.add(new TestU(20180203,"12:12"));
            testUS.add(new TestU(20180103,"12:19"));
            testUS.add(new TestU(20180503,"2:12"));
            testUS.add(new TestU(20180903,"12:19"));
            testUS.add(new TestU(20180903,"12:15"));
            testUS.add(new TestU(20180903,"12:15"));
            Collections.sort(testUS, getComparator());
            System.out.println(testUS.toString());
    
        }
    
        public static Comparator<TestU> getComparator(){
            return (o1,o2) ->{
                try {
                    if (o1.getDate() < o2.getDate()){
                        return -1;
                    } else if (o1.getDate().equals(o2.getDate()) ){
                        if (new SimpleDateFormat("HH:mm").parse(o1.getTime()).before(new SimpleDateFormat("HH:mm").parse(o2.getTime()))){
                            return -1;
                        }
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                return 1;
            };
        }
    }
    @Data
    class TestU {
        Integer date;
        String time;
    
        public TestU(Integer date, String time) {
            this.date = date;
            this.time = time;
        }
    }
    
  • 相关阅读:
    project euler 开坑
    hdu 5382 GCD?LCM!
    Leetcode 557. 反转字符串中的单词 III
    Leetcode 344. 反转字符串
    Leetcode 345. 反转字符串中的元音字母
    008.C++类改写模板类
    007.C++构造函数
    006.C++头文件
    02.树的序列化与反序列化(C++)
    Leetcode 94. 二叉树的中序遍历
  • 原文地址:https://www.cnblogs.com/bihanghang/p/10272930.html
Copyright © 2011-2022 走看看