格列高利历
嘿伙计们,我知道这是一个非常简单的问题,但我是 Java 新手,所以请耐心等待。我创建了一个程序,可以计算一本书发行后返回的时间!所以请帮帮我。
这是我的代码片段:
public void loan(int numOfDays) {
if( onLoan == true) {
System.out.println("Already on Loan, Return Date : "+Calendar.DATE );
}
else {
due.set( numOfDays, Calendar.DATE );
System.out.println("Available");
onLoan = true;
} }
// 将书标记为已退回
我需要替换 Calendar.DATE 才能正确计算。我需要计算 TEST 文件传递的日期并计算它将返回的日期。该项目需要明天提交,所以请帮助我!
Hey guys, I know this is a very simple question but I am new to Java so please bear with me. I have create a program that can calculate the time a book is due to come back after being issued! So please help me out.
Here is the piece of code that I have:
public void loan(int numOfDays) {
if( onLoan == true) {
System.out.println("Already on Loan, Return Date : "+Calendar.DATE );
}
else {
due.set( numOfDays, Calendar.DATE );
System.out.println("Available");
onLoan = true;
} }
// Mark the book as having been returned
I need to replace that Calendar.DATE to get my calculations right. I need to calculate the date passed by the TEST file and calculate the date it will be returned. This project needs to be submitted TOMORROW, so please please help me out!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标准的 java Date API 很痛苦。尽管前面的答案是正确的,并且可能对您来说已经足够了,但我建议您查看 jodaTime 如果你需要处理日期。很多令人头疼的问题都在里面解决了。
The standard java Date API is a pain. Although the previous answer is correct, and might be sufficient for you I suggest taking a look at jodaTime if you need to work with dates. Many of the headaches are solved in there.
您已经接近解决方案了。您正在寻找:
[http ://java.sun.com/javase/6/docs/api/java/util/GregorianCalendar.html#add(int, int)][1]
[1]: http://java.sun.com/javase/6/docs /api/java/util/GregorianCalendar.html#add(int, int)
You're close to the solution. You're looking for:
[http://java.sun.com/javase/6/docs/api/java/util/GregorianCalendar.html#add(int, int)][1]
[1]: http://java.sun.com/javase/6/docs/api/java/util/GregorianCalendar.html#add(int, int)