使用 jodatime 查找剩余日期和时间
我想使用 joda 时间进行比较(查找剩余天数和两天之间的时间)。 我正在使用两个像这样的 DateTime 对象(一个正在开始,另一个正在结束)
DateTime endDate = new DateTime(2011,12,25,0,0,0,0);
DateTime strtDate = new DateTime();
现在我有兴趣找到像这样的剩余日期和时间 天:49小时:5分钟:52秒:45
(这里不考虑年和月..)
现在我继续像这样的周期类
Period period = new Period();
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendSeconds()
.appendMinutes()
.appendHours()
.appendDays()
.appendMonths()
.appendYears()
.printZeroNever()
.toFormatter();
现在我得到的结果是年,月,日, ETC... 在这种情况下,我总是会得到 1-30
之间的天数(而不是 31,45,49...(我想要的))。
那么我怎样才能得到这个东西(有没有我缺少的方法)或者我需要以编程方式处理这个问题,因为我读到 joda 时间非常灵活,所以我非常确定会有这样的方法。
如果您熟悉,请分享您的知识。
I want to compare(finding remaining days and time between two days) using joda time.
I am taking two DateTime object like this(one is starting and another is ending)
DateTime endDate = new DateTime(2011,12,25,0,0,0,0);
DateTime strtDate = new DateTime();
Now i am interested to find remaining date and time like thisdays:49 Hrs:5 Min:52 Sec:45
(Not considering Year and month here..)
Now I go ahead with period class like this
Period period = new Period();
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendSeconds()
.appendMinutes()
.appendHours()
.appendDays()
.appendMonths()
.appendYears()
.printZeroNever()
.toFormatter();
Now in result what i get year,month,Day,etc...
in this case i will get days between 1-30
(not 31,45,49...(which I want)) always.
So how can i get this thing(is there any method that I am missing) or I need to handle this programmatically, as I read that joda time is very flexible so I am very sure that there will be any method like this.
If you are familiar then kindly share your knowledge.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 PeriodType.dayTime 定义从天开始的所有标准字段()。
例如:
示例输出
startDate
和endDate
之间的周期为或
有输出
Defines all standard fields from days downwards with PeriodType.dayTime().
For example :
Sample output
Period between
startDate
andendDate
isOr
with output
如果您希望以更漂亮的格式输出,那么您也可以使用此代码片段
If you want the output in prettier format then you can use this snippet too