2013-08-30 37 views

Trả lời

19

Có phương thức boolean isAfter(ReadableInstant instant) trong ReadableInstant, do đó, khi DateTime triển khai ReadableInstant, nó cũng nên chấp nhận DateTime.

+0

tôi thấy mà quá tải nhưng bỏ qua nó bởi vì tôi đã không kno w Tôi có thể vượt qua trong một 'DateTime' khi nó được mong đợi một' ReadableInstant'. Cảm ơn! –

+2

@Teifi Nếu điều này trả lời câu hỏi của bạn, bạn nên cân nhắc việc chấp nhận. –

+0

Câu trả lời ở trên là một trong những phương pháp tốt nhất để sử dụng –

1
public static void main(String[] args) { 
    System.err.println(new DateTime().isAfter(new DateTime().plusDays(1))); 
} 

công trình đối với tôi

0

Ngoài ra còn có một phương pháp getMillis() thừa hưởng từ BaseDateTime cung cấp cho bạn một giá trị long đại diện cho ngày tháng, bạn có thể so sánh hai long giá trị để xác định đó là trước đây, và bao nhiêu .

+0

Như đã nêu, nếu bạn muốn biết sự khác biệt chính xác giữa hai đối tượng DateTime cho đầu ra bổ sung sau này trong mã. –

2

Phương pháp isAfter Mô tả

public boolean isAfter(ReadableInstant instant) 

    Is this instant after the instant passed in comparing solely by millisecond. 

    Specified by: 
     isAfter in interface ReadableInstant 

    Parameters: 
     instant - an instant to check against, null means now 
    Returns: 
     true if the instant is after the instant passed in 

Phải mất ReadableInstant như là đối số để DateTime cũng có thể được thông qua như là rõ ràng từ DateTime Hierarchy

Class DateTime 

java.lang.Object 
    extended by org.joda.time.base.AbstractInstant 
     extended by org.joda.time.base.AbstractDateTime 
      extended by org.joda.time.base.BaseDateTime 
       extended by org.joda.time.DateTime 

All Implemented Interfaces: 
    Serializable, Comparable<ReadableInstant>, ReadableDateTime, ReadableInstant 

chi tiết Trên đây là được lấy từ joda api docs

+0

Khi [tài liệu] (http://joda-time.sourceforge.net/apidocs/org/joda/time/base/AbstractInstant.html#isAfter (org.joda.time.ReadableInstant)) nói "so sánh chỉ bằng mili giây , "chúng có nghĩa là gì" chỉ bằng mili giây "? Họ chỉ có nghĩa là múi giờ được bỏ qua, phải không? –

Các vấn đề liên quan