关于java:声明一个startdate&

declaring a startdate & endate using joda time?

本问题已经有最佳答案,请猛点这里访问。

我已经导入了joda libary,并且可以导入Easy Reader类。但是,我需要正确的格式设置帮助,这样我可以计算介于和之间的天数,是的,我对mm/dd/yyyy是水化的,但是我使用了整数。我还需要进口其他东西吗?我在佐达是个新手,所以请耐心点,谢谢。一切似乎都很顺利,但我找不到正确的语法来帮助我找出两个日期之间的区别,我也找不到。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
}


这个

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

应该是这样的

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

因为startend已经是LocalDate了,您想保存调用结果。另外,您应该只需要一个EasyReader实例。而且,您需要添加

1
import org.joda.time.Days;