当前位置: 首页>>代码示例>>Java>>正文


Java DateTime.plusMonths方法代码示例

本文整理汇总了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;
}
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:25,代码来源:DatabaseHandler.java

示例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;
}
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:23,代码来源:DatabaseHandler.java

示例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);
    }
}
 
开发者ID:MOLO17,项目名称:CustomizableCalendar,代码行数:19,代码来源:Calendar.java

示例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);
}
 
开发者ID:cbooy,项目名称:cakes,代码行数:36,代码来源:JodaTimeDemo1.java

示例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);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:41,代码来源:LanguageInspectionController.java

示例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));
}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:8,代码来源:MonthlyFragment.java


注:本文中的org.joda.time.DateTime.plusMonths方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。