Questions tagged [periodformatter]

15 questions
8
votes
2 answers

PeriodFormatter not showing days

I am using a PeriodFormatter to return a string showing the time until an event. The code below keeps creating strings like 1146 hours 39 minutes instead of x days y hours z minutes. Any ideas? Thanks, Nathan PeriodFormatter formatter = new…
Nath5
  • 1,665
  • 5
  • 28
  • 46
4
votes
1 answer

Understanding joda time PeriodFormatter

I thought I understand it, but apparently I don't. Can you help me make these unit tests pass? @Test public void second() { assertEquals("00:00:01", OurDateTimeFormatter.format(1000)); } @Test public void minute() { assertEquals("00:01:00",…
ripper234
  • 222,824
  • 274
  • 634
  • 905
3
votes
2 answers

Displaying "negative" time periods with Joda-Time PeriodFormatter

I'm using joda-time (1.6.2) on a project and one of the things I'm doing is getting the difference between a predicted time and an actual time. Sometimes this difference is positive, sometimes negative. While the appropriate approach may be to…
Befloibent
  • 33
  • 1
  • 3
3
votes
3 answers

Convert hours, mins, secs String to hours

I want to convert a time in the below format into hours. My input which is a time format could be anything like 1 hour 30 mins 20 secs 2 hrs 10 mins 45 mins whereas my output will be: 1.505 2.167 0.75 These are the hours. Currently I am doing…
Tiya
  • 553
  • 8
  • 26
2
votes
2 answers

Joda Period Formatter

System.out.println( PeriodFormat.getDefault().print(Period.hours(1).plusMinutes(30).plusSeconds(60))); The output from the above Joda PeriodFormatter is "1 hour, 30 minutes and 60 seconds". I know that this is a fringe case, but is there a way to…
GWTNewbie
  • 395
  • 4
  • 16
2
votes
1 answer

jodatime - PeriodFormatter: suffix only for day/days

I need only to show suffix for day/days, how can I achieve that? It doesn't work: java.lang.IllegalStateException: No field to apply suffix to.. private PeriodFormatter getDayTextFormatter() { return new PeriodFormatterBuilder() …
AppiDevo
  • 3,195
  • 3
  • 33
  • 51
2
votes
1 answer

Different behavior of PeriodFormatter on different devices (JodaTime)

I'm implementing count down timer for the android app using JodaTime. Depending of devices the output is different. DateTime openingDateTime = new DateTime(2018, DateTimeConstants.JUNE, 14, 21, 0, 0, DateTimeZone.forID("Europe/Moscow")); …
AppiDevo
  • 3,195
  • 3
  • 33
  • 51
1
vote
2 answers

ISOPeriodFormat.standard().parsePeriod("12:00:00") Exception

I try to call the parsePeriod() with the parameter "12:00:00", and it runs an IllegalArgumentException. I try the decompile the PeriodFormatter class, and getParser().parseInto(localMutablePeriod, paramString, 0, iLocale); this line turns wrong. Can…
Goroyal
  • 171
  • 1
  • 9
1
vote
1 answer

Joda time - Not able to calculate months / years from Period in minutes

Am using joda-time-2.5 in Android Studio project. I am not able to work out what I missing to be able to correctly format a String with years and/or months. The Period calculates correctly - but will not go beyond "Weeks" eg. 1000000 minutes is…
0
votes
1 answer

PeriodFormmater in joda time

Is it possible that a duration is formatted like following. 8 hours will be considered as a day. 5 days considered as a week so 28800*1000 seconds duration will give output as 1d on periodformatting
GJoshi
  • 141
  • 2
  • 9
0
votes
1 answer

jodaTime PeriodFormatter not formatting correctly

I have this PeriodFormatter: PeriodFormatterBuilder() .appendDays() .appendSuffix( " day", " days") ) .appendSeparator(", ") .printZeroRarelyLast() …
André
  • 143
  • 1
  • 14
0
votes
2 answers

How to use Period.parse()?

Period.parse() requires API level 26. Is there any workaround to use it with minimum API level 17. I am using Period snoozeTime = Period.parse(rs.getString(rs.getColumnIndex("snoozeTime")));
Shunan
  • 3,165
  • 6
  • 28
  • 48
0
votes
1 answer

JodaTime PeriodFormatter

I have the following PeriodFormatter: PeriodFormatter periodFormatter = new PeriodFormatterBuilder().printZeroAlways().minimumPrintedDigits(2).appendHours().appendSeparator(":") …
quma
  • 5,233
  • 26
  • 80
  • 146
0
votes
1 answer

Joda Time how to calculate how much time left?

In this part of my code I want Joda Time to calculate and show how much time left until next birthday. So the year should change on birthday DateTime startDate = DateTime.now(); DateTime endDate = new DateTime(x,m110,d110,h120,min120); Period period…
0
votes
2 answers

Java JodaTime: "123" should be (long) 123. How can I do that without having "ms" for example at the end: "10ms"?

How do I format the PeriodFormatter from Java-JodaTime to handle Strings like: "10s" = (long) 10000; <-- I solved that. "10ms" = (long) 10. "10" = long 10. <-- Only here is my problem! I can handle the first two commands with Joda Time with this…
AlexHH
  • 51
  • 1
  • 4