承担多余的风险,我想知道如何减去2个日期值并将结果存储在整数中。我正在使用Java进行此练习。
答案 0 :(得分:2)
LocalDate d1 = LocalDate.of(2017, 05, 01);
LocalDate d2 = LocalDate.of(2017, 05, 18);
System.out.println(ChronoUnit.DAYS.between(d1, d2));
您可以使用
获取实际日期LocalDate d1 = LocalDate.now()
答案 1 :(得分:1)
如果您有两个 <script src="https://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js"></script>
<div class="container">
<div class="heading">
<h1 class="heading-child">All I Want is Whirled Peas!</h1>
</div>
<div class="navigation">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Account</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
<div class="content">
<div class="content-heading"><strong>Welcome</strong></div>
This is content of the content section. This is content of the content section. This is content of the content section. This is content of the content section. This is content of the content section. This is content of the content section. This is content of the content section. This is content of the content section. This is content of the content section. This is content of the content section.
</div>
<div class="sidebar-heading">
<div class="sidebar-heading-child"><strong>Additional Info</strong></div>
</div>
<div class="sidebar-content">
Hello this is sidebar content. Hello this is sidebar content. Hello this is sidebar content. Hello this is sidebar content. Hello this is sidebar content. Hello this is sidebar content. Hello this is sidebar content. Hello this is sidebar content. Hello this is sidebar content. Hello this is sidebar content.
</div>
<div class="footer">
<div class="footer-child">Website created by Josh © 2017</div>
</div>
</div>
,则可以使用:
LocalDate
请注意longs days = ChronoUnit.DAYS.between(date1, date2);
做了不同的事情:在一年零一天的时间内,Period::getDays
将返回1,而不是366!