當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。