从现在到DateMidnight课程获取剩余天数

时间:2013-06-23 11:40:36

标签: java jodatime

我的截止日期为DateMidnight类型 - DateMidnight return_due_date,我想计算从现在起到此日期为止的剩余天数。

我该如何计算?

DateMidnight documentation

4 个答案:

答案 0 :(得分:4)

int days = org.joda.time.Days.daysBetween(DateMidnight.now(), yourDueDate).getDays(); 

答案 1 :(得分:1)

使用org.joda.time.Days课程。它提供了一些daysBetween方法来准确计算您的需求。

DateMidnight midnight = return_due_date; // your DateMidnight instance
DateTime now = new DateTime();

int daysBetween = Days.daysBetween(now, midnight).getDays();

答案 2 :(得分:0)

这就是它的完成方式:

import org.joda.time.DateMidnight;
import org.joda.time.DateTime;
import org.joda.time.Days;


public class example {

/**
 * How many days until a certain date.
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    DateMidnight someDate = new DateMidnight(2013,6,26);
    System.out.println("An example due date: "+someDate);
    DateTime timeNow = new DateTime();
    System.out.println("The time right now: "+timeNow);
    int daysToDeadLine = Days.daysBetween(timeNow, someDate).getDays();
    System.out.println("Days until deadline: "+daysToDeadLine);

}}

我还可以建议您下次再努力吗? :)

答案 3 :(得分:0)

这里简单而简单为此目的的好图书馆
https://code.google.com/p/stringtotime/