1月 162020
 

Java中日期格式化yyyyMMdd和YYYYMMdd的区别

示例代码:

 public static void main(String[] args) {
        //YYYY 是表示:当天所在的周属于的年份,一周从周日开始,周六结束,只要本周跨年,那么这周就算入下一年。
        //2019-12-29至2020-1-4跨年周
        Calendar calendar = Calendar.getInstance();
        //2019-12-28
        calendar.set(2019, Calendar.DECEMBER, 28);  
        Date strDate1 = calendar.getTime(); 
        //2019-12-29
        calendar.set(2019, Calendar.DECEMBER, 29);  
        Date strDate2 = calendar.getTime(); 
        // 2019-12-31  
        calendar.set(2019, Calendar.DECEMBER, 31);  
        Date strDate3 = calendar.getTime();  
        // 2020-01-01  
        calendar.set(2020, Calendar.JANUARY, 1);  
        Date strDate4 = calendar.getTime();  
        
        DateFormat df1 = new SimpleDateFormat("yyyyMMdd");
        DateFormat df2 = new SimpleDateFormat("YYYYMMdd");
        //yyyyMMdd
        System.out.println("yyyyMMdd");
        System.out.println("2019-12-28: " + df1.format(strDate1)); 
        System.out.println("2019-12-29: " + df1.format(strDate2)); 
        System.out.println("2019-12-31: " + df1.format(strDate3));  
        System.out.println("2020-01-01: " + df1.format(strDate4));  
        //YYYYMMdd
        System.out.println("YYYYMMdd");
        System.out.println("2019-12-28: " + df2.format(strDate1));
        System.out.println("2019-12-29: " + df2.format(strDate2));
        System.out.println("2019-12-31: " + df2.format(strDate3));  
        System.out.println("2020-01-01: " + df2.format(strDate4));
    }

输出结果: Continue reading »

1月 112020
 

内容转自:https://blog.csdn.net/yangshijin1988/article/details/51698061/

greatest(字段1,字段2,字段3,..,字段n)  取最大值

least(字段1,字段2,字段3,…,字段n)   取最小值

示例:

SELECT GREATEST(2,3,4);   结果:4
SELECT LEAST(2,3,4);   结果:2

SELECT GREATEST(DATE(‘2016-05-02’), DATE(‘2015-05-02’), DATE(‘2017-05-02’));   结果:2017-05-02
SELECT LEAST(DATE(‘2016-05-02’), DATE(‘2015-05-02’), DATE(‘2017-05-02’));   结果:2015-05-02