格列高利历

发布于 2024-08-30 22:39:42 字数 465 浏览 4 评论 0原文

嘿伙计们,我知道这是一个非常简单的问题,但我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宁愿没拥抱 2024-09-06 22:39:42

标准的 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.

却一份温柔 2024-09-06 22:39:42

您已经接近解决方案了。您正在寻找:

YOUR_CALENDAR_INSTANCE.add(numOfDays, Calendar.DAY_OF_MONTH);

[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:

YOUR_CALENDAR_INSTANCE.add(numOfDays, Calendar.DAY_OF_MONTH);

[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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文