代码之家  ›  专栏  ›  技术社区  ›  Moses Apostol

使用joda时间声明startdate和EndDate?[副本]

  •  -1
  • Moses Apostol  · 技术社区  · 7 年前

    import org.joda.time.DateTime;
    import org.joda.time.DateTimeZone;
    import org.joda.time.LocalDate;
    class starter{
    public static void BdayPrgm(String args[]){
    
    System.out.println("Please Enter Today's Month: ");
            EasyReader month = new EasyReader();
            //this will indentify it as an INT, not a string.
            //quest is a question btw.
            todaysmon = month.readInt();
    
            System.out.println("What number is today?: ");
            EasyReader currentday = new EasyReader();
            todayday = currentday.readInt();
    
    
    
            System.out.println("What is today's year?: ");
            EasyReader todayyear = new EasyReader();
            year = todayyear.readInt();
    
            System.out.println("");
    
            System.out.println("What is your BdayMonth?: ");
            EasyReader thatyear = new EasyReader();
            bdaymon = thatyear.readInt();
    
            System.out.println("What is your Bday #?: ");
            EasyReader thatday = new EasyReader();
            thatgr8day = thatday.readInt();
    
            System.out.println("What is the bdayyear?: ");
            EasyReader bdayyear = new EasyReader();
            bdayyr = bdayyear.readInt();
    
    
            int age;
            age = year - bdayyr;
    
    
            //we can get start date by putting test maybe?
            DateTimeZone LA = DateTimeZone.forID("America/Los_Angeles");
            LocalDate start = new LocalDate(year,todaysmon,todayday);
            LocalDate end = new LocalDate(year,bdaymon,thatgr8day);
    
            int Days;
            //code isn't compileing below. I don't know what I'm doing wrong.
            Days.daysBetween(new LocalDate(start),new LocalDate(end)).getDays();
    
            //int days = d.getdays;
    
            System.out.println("");
    
            System.out.println(CELEB1+" is going to be "+age+" years old in X days!");
    

    }

    }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Elliott Frisch    7 年前

    int Days;
    Days.daysBetween(new LocalDate(start),new LocalDate(end)).getDays();
    

    int dayCount = Days.daysBetween(start, end).getDays();
    

    因为 start end LocalDate (s) 您想保存通话结果。此外,您只需要 EasyReader . 您需要添加

    import org.joda.time.Days;