Ros*_*Jha 4 java android jodatime
我想用joda时间比较(找出两天之间的剩余天数和时间).我正在采取两个这样的DateTime对象(一个正在启动而另一个正在结束)
DateTime endDate = new DateTime(2011,12,25,0,0,0,0);
DateTime strtDate = new DateTime();
Run Code Online (Sandbox Code Playgroud)
现在我有兴趣找到这样的剩余日期和时间
days:49 Hrs:5 Min:52 Sec:45(不考虑这里的年份和月份..)
现在我像这样继续上课
Period period = new Period();
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendSeconds()
.appendMinutes()
.appendHours()
.appendDays()
.appendMonths()
.appendYears()
.printZeroNever()
.toFormatter();
Run Code Online (Sandbox Code Playgroud)
现在结果是我得到年,月,日等...在这种情况下,我将得到之间的日子1-30(不是31,45,49 ...(我想要)).
那么我怎么能得到这个东西(有没有我缺少的方法)或者我需要以编程方式处理这个,因为我读到joda时间非常灵活所以我非常确定会有这样的方法.
如果您熟悉,那么请分享您的知识.
lsc*_*hin 14
使用PeriodType.dayTime()定义从天数开始的所有标准字段.
例如:
DateTime startDate = DateTime.now(); // now() : since Joda Time 2.0
DateTime endDate = new DateTime(2011, 12, 25, 0, 0);
Period period = new Period(startDate, endDate, PeriodType.dayTime());
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendDays().appendSuffix(" day ", " days ")
.appendHours().appendSuffix(" hour ", " hours ")
.appendMinutes().appendSuffix(" minute ", " minutes ")
.appendSeconds().appendSuffix(" second ", " seconds ")
.toFormatter();
System.out.println(formatter.print(period));
Run Code Online (Sandbox Code Playgroud)
样本输出
间期startDate和endDate是
47天12小时46分47秒
要么
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendPrefix("Day:", " Days:").appendDays()
.appendPrefix(" Hour:", " Hours:").appendHours()
.appendPrefix(" Minute:", " Minutes:").appendMinutes()
.appendPrefix(" Second:", " Seconds:").appendSeconds()
.toFormatter();
Run Code Online (Sandbox Code Playgroud)
与输出
天:47小时:12分钟:46秒:47
| 归档时间: |
|
| 查看次数: |
3491 次 |
| 最近记录: |