Chcę odjąć 1 godzinę od DateTime
Próbowałem wyszukać go w Google i odkryłem, że istnieje metoda o nazwie minus, która pobiera kopię daty i zajmuje określony czas tutaj: http://www.joda.org/joda-time/apidocs/org/joda/time/DateTime.html#minus(long)minus 1 godzina do DateTime przy użyciu Joda Time
Ale nie wiem jak tego używać i nie mogę znaleźć przykładu w Internecie.
Oto mój kod: Dane
String string1 = (String) table_4.getValueAt(0, 1);
String string2= (String) table_4.getValueAt(0, 2);
DateTimeFormatter dtf = DateTimeFormat.forPattern("hh:mm a").withLocale(Locale.ENGLISH);
DateTime dateTime1 = dtf.parseDateTime(string1.toString());
DateTime dateTime2 = dtf.parseDateTime(string2.toString());
final String oldf = ("hh:mm a");
final String newf= ("hh.mm 0");
final String newf2= ("hh.mm a");
final String elapsedformat = ("hh.mm");
SimpleDateFormat format2 = new SimpleDateFormat(oldf);
SimpleDateFormat format2E = new SimpleDateFormat(newf);
Period timePeriod = new Period(dateTime1, dateTime2);
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendHours().appendSuffix(".")
.appendMinutes().appendSuffix("")
.toFormatter();
String elapsed = formatter.print(timePeriod);
table_4.setValueAt(elapsed,0,3);
DecimalFormat df = new DecimalFormat("00.00");
System.out.println(dateTime1);
table_4.setValueAt("", 0, 4);
table_4.setValueAt("", 0, 5);
Próbka:
dateTime1: 08:00 AM
dateTime2: 05:00 PM
okres będzie 9 godzin. ale chcę, żeby było 8 godzin tylko dlatego, że chcę odjąć przerwę obiadową w moim programie.
próbowałem go z tego głupiego kodu:
dateTime1.minus(-1)
Próbowałem też parsowania string1
podwoić więc mogę odjąć ją o jeden.
double strindtoD = Integer.parseInt(string1);
Próbowałem też co innego DateTime
i używać okres, aby uzyskać różnicę dwóch czasie
String stringOneHour = ("01:00 AM");
DateTime dateTime3 = dtf.parseDateTime(stringOneHour.toString());
Period timePeriod = new Period(dateTime3, dateTime1);
nope to nie działa .. – Maguzu
Uhwhat? Pewnie, że tak. Używam go i działa dobrze. Musi być coś jeszcze, czego nie robisz dobrze ... Zauważ niezmienność! – fge
'DateTime odjęta = dateTime1.minus (Period.hours (1)); to działa, ale jak używać jako parametru w okresie' Period periodFaggot = new Period (dateTime1, dateTime2); \t \t \t \t \t \t PeriodFormatter formater = nowy PeriodFormatterBuilder() \t \t .appendHours(). AppendSuffix (" "). \t \t .appendMinutes(). AppendSuffix ("") \t \t .toFormatter(); \t Łańcuch upłynął = formatter.print (periodFaggot); ' – Maguzu