Expiration Date control program
This question already has an answer here:
Java has a built in date class which has many problematic issues, so it is not worth using. Instead, the Joda-Time api offers a reliable Java date and time API.
The API and some information about it can be found at http://www.joda.org/joda-time/.
A similar question has been asked already, and some answers and some example codes can be found at Number of days between two dates in Joda-Time.
For your case, instantiating a new time with a default constructor will give the system time: DateTime dt = new DateTime();
Once you get the expiration date from the database, just compare it to the system time as described in the question linked in my answer.
If you are code in Java that will be hard 'cause you can easily decompile java and remove that part.
Maybe this:
public int DaysLeft(long DBDateTimeStamp) //Unix time
{
long curr = System.currentTimeMillis()/1000;
long left = DBDateTimeStamp - curr;
int left = left / (60*60*24);
return left;
}
or something like that.
链接地址: http://www.djcxy.com/p/36652.html上一篇: 使用joda time api计算两个日期之间的天数
下一篇: 到期日期控制程序