本文整理汇总了Java中org.joda.time.DateTime.plusMonths方法的典型用法代码示例。如果您正苦于以下问题:Java DateTime.plusMonths方法的具体用法?Java DateTime.plusMonths怎么用?Java DateTime.plusMonths使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.DateTime
的用法示例。
在下文中一共展示了DateTime.plusMonths方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAverageGlucoseReadingsByMonth
import org.joda.time.DateTime; //导入方法依赖的package包/类
public List<Integer> getAverageGlucoseReadingsByMonth() {
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 months is at least 1 since we do have average for the current week even if incomplete
int monthsNumber = Months.monthsBetween(minDateTime, maxDateTime).getMonths() + 1;
for (int i = 0; i < monthsNumber; i++) {
newDateTime = currentDateTime.plusMonths(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: getGlucoseDatetimesByMonth
import org.joda.time.DateTime; //导入方法依赖的package包/类
public List<String> getGlucoseDatetimesByMonth() {
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> finalMonths = new ArrayList<String>();
// The number of months is at least 1 because current month is incomplete
int monthsNumber = Months.monthsBetween(minDateTime, maxDateTime).getMonths() + 1;
DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
for (int i = 0; i < monthsNumber; i++) {
newDateTime = currentDateTime.plusMonths(1);
finalMonths.add(inputFormat.format(newDateTime.toDate()));
currentDateTime = newDateTime;
}
return finalMonths;
}
示例3: Calendar
import org.joda.time.DateTime; //导入方法依赖的package包/类
public Calendar(DateTime firstMonth, DateTime lastMonth) {
this.firstMonth = firstMonth;
this.firstDayOfWeek = java.util.Calendar.getInstance(Locale.getDefault()).getFirstDayOfWeek();
DateTime startMonth = firstMonth.plusMonths(1);
int monthsBetweenCount = Months.monthsBetween(firstMonth, lastMonth).getMonths();
months = new ArrayList<>();
months.add(firstMonth);
currentMonth = firstMonth;
DateTime monthToAdd = new DateTime(startMonth.getYear(), startMonth.getMonthOfYear(), 1, 0, 0);
for (int i = 0; i <= monthsBetweenCount; i++) {
months.add(monthToAdd);
monthToAdd = monthToAdd.plusMonths(1);
}
}
示例4: testTimePlus
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 时间加减操作,plus 负数时是向前推移
*/
@Test
public void testTimePlus() {
// 获取当前时间
DateTime dt = new DateTime();
String currentTime = dt.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("currentTime: " + currentTime);
// 相对当前时间 向后5天,5天后
DateTime plus5Days = dt.plusDays(5);
String plus5DaysStr = plus5Days.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("plus 5 days: " + plus5DaysStr);
// 相对当前时间 向后5个小时,5小时后
DateTime plus5Hours = dt.plusHours(5);
String plus5HoursStr = plus5Hours.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("plus 5 hours: " + plus5HoursStr);
// 相对当前时间,向后5分钟,5分钟后
DateTime plus5Minutes = dt.plusMinutes(5);
String plus5MinutesStr = plus5Minutes.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("plus 5 minutes: " + plus5MinutesStr);
// 相对当前时间,向前5年,5年前
DateTime plus5Years = dt.plusYears(-5);
String plus5YearsStr = plus5Years.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("5 years ago: " + plus5YearsStr);
// 相对当前时间,向前5个月
DateTime plusMonths = dt.plusMonths(-5);
String plusMonthsStr = plusMonths.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("5 month ago: " + plusMonthsStr);
}
示例5: listInspections
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Dynamic(value = "inspector or admin", meta = "pattern=CAN_INSPECT_LANGUAGE,role=ADMIN,anyMatch=true")
public Result listInspections(Optional<String> month, Optional<Long> start, Optional<Long> end) {
ExpressionList<LanguageInspection> query = Ebean.find(LanguageInspection.class)
.fetch("exam")
.fetch("exam.course")
.fetch("exam.creator", "firstName, lastName, email, userIdentifier")
.fetch("exam.parent.examOwners", "firstName, lastName, email, userIdentifier")
.fetch("statement")
.fetch("creator", "firstName, lastName, email, userIdentifier")
.fetch("assignee", "firstName, lastName, email, userIdentifier")
.where()
.ne("exam.state", Exam.State.DELETED);
if (start.isPresent() || end.isPresent()) {
long x = 100;
if (start.isPresent()) {
DateTime startDate = new DateTime(start.get()).withTimeAtStartOfDay();
query = query.ge("finishedAt", startDate.toDate());
}
if (end.isPresent()) {
DateTime endDate = new DateTime(end.get()).plusDays(1).withTimeAtStartOfDay();
query = query.lt("finishedAt", endDate.toDate());
}
} else if (month.isPresent()) {
DateTime startWithMonth = DateTime.parse(month.get()).withDayOfMonth(1).withMillisOfDay(0);
DateTime endWithMonth = startWithMonth.plusMonths(1);
query = query.between("finishedAt", startWithMonth.toDate(), endWithMonth.toDate());
} else {
DateTime beginningOfYear = DateTime.now().withDayOfYear(1);
query = query
.disjunction()
.isNull("finishedAt")
.gt("finishedAt", beginningOfYear.toDate())
.endJunction();
}
List<LanguageInspection> inspections = query.findList();
return ok(inspections);
}
示例6: onResume
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public void onResume() {
super.onResume();
DateTime begMonth = DateTime.now().withDayOfMonth(1);
DateTime endMonth = begMonth.plusMonths(1);
journalFragment.filterTripByDate(new Interval(begMonth, endMonth));
}