Get first next Monday after certain date?(在特定日期之后的下周一获得第一个?)
问题描述
我知道这里也有同样的问题,但我试过了提供的答案,它返回了一个我不明白的输出.我对答案感到困惑,我认为输出不正确.
I know there is the same question here, but I have tried the answer provided and it returned an output that I don't understand. I am confused by the answer and I don't think the output is correct.
我需要帮助,谢谢:)
这是输出:
我应该提取输出的哪个位置来检索星期一的日期?
Where on the output should I extract to retrieve Monday's date?
推荐答案
Java 8+
哪些打印...
因为我的实际日期可能是星期一,所以您也可以使用...
Because it's possible that the date my actually be a Monday, you could also use...
Java <= 7
您应该使用 ThreeTen Backport,它为您提供 Java 8 Date/的支持时间接口
Java <= 7
You should be using the ThreeTen Backport, which gives you the support of the Java 8 Date/Time API
代替 System.out.println(date1);
使用 System.out.println(date1.getTime());
getTime
返回一个 Date
的实例,它表示 Calendar
getTime
returns an instance of Date
which represents the current state of the Calendar
这将输出 Mon Jul 14 00:00:00 EST 2014
System.out.println(date1)
等价于使用 System.out.println(date1.toString())
,在本例中为转储一堆关于 Calendar
对象状态的有用信息,但不是真正的人类可读数据.
System.out.println(date1)
is the equivlent of using System.out.println(date1.toString())
, which, in this case, is dumping a bunch of useful info about the state of the Calendar
object, but not really human readable data.
System.out.println(date1.getTime())
将使用 Date
的 to toString
方法来显示日期值, 根据当前的本地设置格式化,这将提供更多有用的信息.
System.out.println(date1.getTime())
will use the Date
's to toString
method to display a date value, formatted based on the current local settings, which will provide more useful information.
更新
不要使用GregorianCalendar
,而应该使用系统Calendar
,例如...
Instead of using GregorianCalendar
, you should use the system Calendar
, for example...
此外,月份是 0
索引的,这意味着 Janurary 实际上是 0
而不是 1
,因此在您的示例中,您指定了月份为 7 月,而不是 6 月.
Also, months are 0
indexed, meaning that Janurary is actually 0
not 1
, so in your example, you've specified the month as July, not June.
所以,相反,使用...
So, instead, using...
哪个输出了...
从今天开始是下周一...或多或少 ;)
Which is next Monday from today...more or less ;)
这篇关于在特定日期之后的下周一获得第一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!