How to get Date object in “YYYY-MM-DD” format in android

后端 未结 5 1534
借酒劲吻你
借酒劲吻你 2021-02-18 20:04

I have a requirement that I need to compare two Dates. One Date will come from DB which is String in \"YYYY-DD-MM\" firm and I need to compare this String Date with current Date

5条回答
  •  执笔经年
    2021-02-18 20:27

    You can do it in following way

    // pick current system date
    
        Date dt = new Date();
    
    // set format for date
    
       SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    
     // parse it like
    
            String check = dateFormat.format(dt);
    
    
            System.out.println("DATE TO FROM DATEBASE   " + 
                    arrayOfStringDate[d].toString());
            System.out.println("CURRENT DATE   " + check);
    

    // and compare like

    System.out.println("compare    "+ 
            arrayOfStringDate[d].toString().equals(check));
    

提交回复
热议问题