• Tags ,         
  • 2018-03-19  11:07:56        
  • 51 °C    
    import java.util.Calendar;
    
    class YesterdayCurrent {
        public static void main(String[] args){
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.DATE, -1);
            System.out.println(cal.getTime());
        }
    }

    在Java 8中,可以用下面的代码实现相同的功能。

    import java.time.LocalDateTime;
    
    class YesterdayCurrent {
    
        public static void main(String[] args) {
            LocalDateTime today = LocalDateTime.now();
            LocalDateTime yesterday = today.minusDays(1);
    
            System.out.println(yesterday);
        }
    }
     
    转载请保留页面地址:https://www.breakyizhan.com/javamianshiti/2427.html