本文整理匯總了Java中org.joda.time.DateTime.plusWeeks方法的典型用法代碼示例。如果您正苦於以下問題:Java DateTime.plusWeeks方法的具體用法?Java DateTime.plusWeeks怎麽用?Java DateTime.plusWeeks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.DateTime
的用法示例。
在下文中一共展示了DateTime.plusWeeks方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAverageGlucoseReadingsByWeek
import org.joda.time.DateTime; //導入方法依賴的package包/類
public List<Integer> getAverageGlucoseReadingsByWeek() {
JodaTimeAndroid.init(mContext);
DateTime maxDateTime = new DateTime(realm.where(GlucoseReading.class).maximumDate("created").getTime());
DateTime minDateTime = new DateTime(realm.where(GlucoseReading.class).minimumDate("created").getTime());
DateTime currentDateTime = minDateTime;
DateTime newDateTime = minDateTime;
ArrayList<Integer> averageReadings = new ArrayList<Integer>();
// The number of weeks is at least 1 since we do have average for the current week even if incomplete
int weeksNumber = Weeks.weeksBetween(minDateTime, maxDateTime).getWeeks() + 1;
for (int i = 0; i < weeksNumber; i++) {
newDateTime = currentDateTime.plusWeeks(1);
RealmResults<GlucoseReading> readings = realm.where(GlucoseReading.class)
.between("created", currentDateTime.toDate(), newDateTime.toDate())
.findAll();
averageReadings.add(((int) readings.average("reading")));
currentDateTime = newDateTime;
}
return averageReadings;
}
示例2: getGlucoseDatetimesByWeek
import org.joda.time.DateTime; //導入方法依賴的package包/類
public List<String> getGlucoseDatetimesByWeek() {
JodaTimeAndroid.init(mContext);
DateTime maxDateTime = new DateTime(realm.where(GlucoseReading.class).maximumDate("created").getTime());
DateTime minDateTime = new DateTime(realm.where(GlucoseReading.class).minimumDate("created").getTime());
DateTime currentDateTime = minDateTime;
DateTime newDateTime = minDateTime;
ArrayList<String> finalWeeks = new ArrayList<String>();
// The number of weeks is at least 1 since we do have average for the current week even if incomplete
int weeksNumber = Weeks.weeksBetween(minDateTime, maxDateTime).getWeeks() + 1;
DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
for (int i = 0; i < weeksNumber; i++) {
newDateTime = currentDateTime.plusWeeks(1);
finalWeeks.add(inputFormat.format(newDateTime.toDate()));
currentDateTime = newDateTime;
}
return finalWeeks;
}
示例3: secondsUntilNextMondayRun
import org.joda.time.DateTime; //導入方法依賴的package包/類
private int secondsUntilNextMondayRun() {
DateTime now = DateTime.now();
// Every Monday at 5AM UTC
int adjustedHours = 5;
if (!AppUtil.getDefaultTimeZone().isStandardOffset(now.getMillis())) {
// Have the run happen an hour earlier to take care of DST offset
adjustedHours -= 1;
}
DateTime nextRun = now.withHourOfDay(adjustedHours)
.withMinuteOfHour(0)
.withSecondOfMinute(0)
.withMillisOfSecond(0)
.plusWeeks(now.getDayOfWeek() == DateTimeConstants.MONDAY ? 0 : 1)
.withDayOfWeek(DateTimeConstants.MONDAY);
if (!nextRun.isAfter(now)) {
nextRun = nextRun.plusWeeks(1); // now is a Monday after scheduled run time -> postpone
}
// Case for: now there's no DST but by next run there will be.
if (adjustedHours == 5 && !AppUtil.getDefaultTimeZone().isStandardOffset(nextRun.getMillis())) {
nextRun = nextRun.minusHours(1);
}
// Case for: now there's DST but by next run there won't be
else if (adjustedHours != 5 && AppUtil.getDefaultTimeZone().isStandardOffset(nextRun.getMillis())) {
nextRun = nextRun.plusHours(1);
}
Logger.info("Scheduled next weekly report to be run at {}", nextRun.toString());
// Increase delay with one second so that this won't fire off before intended time. This may happen because of
// millisecond-level rounding issues and possibly cause resending of messages.
return Seconds.secondsBetween(now, nextRun).getSeconds() + 1;
}