當前位置: 首頁>>代碼示例>>Java>>正文


Java GregorianCalendar.add方法代碼示例

本文整理匯總了Java中java.util.GregorianCalendar.add方法的典型用法代碼示例。如果您正苦於以下問題:Java GregorianCalendar.add方法的具體用法?Java GregorianCalendar.add怎麽用?Java GregorianCalendar.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.GregorianCalendar的用法示例。


在下文中一共展示了GregorianCalendar.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getToday

import java.util.GregorianCalendar; //導入方法依賴的package包/類
Pair<Date, Date> getToday() {
    final GregorianCalendar today = new GregorianCalendar();
    today.set(Calendar.HOUR_OF_DAY, today.getActualMaximum(Calendar.HOUR_OF_DAY));
    today.set(Calendar.MINUTE, today.getActualMaximum(Calendar.MINUTE));
    today.set(Calendar.SECOND, today.getActualMaximum(Calendar.SECOND));
    today.set(Calendar.MILLISECOND, today.getActualMaximum(Calendar.MILLISECOND));

    final Date end = today.getTime();
    today.add(Calendar.DATE, -1);
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);

    return new Pair<>(today.getTime(), end);
}
 
開發者ID:PacktPublishing,項目名稱:Hands-On-Android-UI-Development,代碼行數:17,代碼來源:AllowanceOverviewPresenter.java

示例2: Test4096539

import java.util.GregorianCalendar; //導入方法依賴的package包/類
public void Test4096539() {
    int[] y = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    for (int x = 0; x < 12; x++) {
        GregorianCalendar gc = new GregorianCalendar(1997, x, y[x]);
        int m1, m2;
        log((m1 = gc.get(MONTH) + 1) + "/"
                + gc.get(DATE) + "/" + gc.get(YEAR)
                + " + 1mo = ");

        gc.add(MONTH, 1);
        logln((m2 = gc.get(MONTH) + 1) + "/"
                + gc.get(DATE) + "/" + gc.get(YEAR)
        );
        int m = (m1 % 12) + 1;
        if (m2 != m) {
            errln("Fail: Want " + m + " Got " + m2);
        }
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:CalendarRegression.java

示例3: getThisWeek

import java.util.GregorianCalendar; //導入方法依賴的package包/類
Pair<Date, Date> getThisWeek() {
    final GregorianCalendar today = new GregorianCalendar();
    today.set(Calendar.HOUR_OF_DAY, today.getActualMaximum(Calendar.HOUR_OF_DAY));
    today.set(Calendar.MINUTE, today.getActualMaximum(Calendar.MINUTE));
    today.set(Calendar.SECOND, today.getActualMaximum(Calendar.SECOND));
    today.set(Calendar.MILLISECOND, today.getActualMaximum(Calendar.MILLISECOND));

    final Date end = today.getTime();
    today.add(Calendar.DATE, -(today.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY));

    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);

    return new Pair<>(today.getTime(), end);
}
 
開發者ID:PacktPublishing,項目名稱:Hands-On-Android-UI-Development,代碼行數:18,代碼來源:AllowanceOverviewPresenter.java

示例4: preRegChange

import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
 * Действия по смене выбранного дня и услуги для предвариловки.
 */
private void preRegChange(boolean force) {
    if (!force && (comboBoxServices == null
        || comboBoxServices.getSelectedItem() == null
        || (calPrereg.getDate().equals(preDate) && comboBoxServices.getSelectedItem()
        .equals(preService))
        || !((QService) comboBoxServices.getSelectedItem()).isLeaf())) {
        tablePreReg.setModel(new DefaultTableModel());
        return;
    }
    preDate = calPrereg.getDate();
    labelPreDate.setText(Locales.getInstance().format_dd_MMMM_yyyy.format(preDate));
    preService = (QService) comboBoxServices.getSelectedItem();

    calPrereg.setMinSelectableDate(new Date());
    if (preService.getAdvanceLimitPeriod() != 0) {
        final GregorianCalendar gc = new GregorianCalendar();
        gc.add(GregorianCalendar.DAY_OF_YEAR, preService.getAdvanceLimitPeriod());
        calPrereg.setMaxSelectableDate(gc.getTime());
    }

    final RpcGetGridOfDay.GridDayAndParams greed = NetCommander
        .getPreGridOfDay(netProperty, preService.getId(), preDate, -1);
    tablePreReg.setModel(new PreTableModel(greed));
    tablePreReg.getColumnModel().getColumn(0).setMaxWidth(50);
    tablePreReg.getColumnModel().getColumn(1).setMaxWidth(110);
}
 
開發者ID:bcgov,項目名稱:sbc-qsystem,代碼行數:30,代碼來源:FReception.java

示例5: getSaturday

import java.util.GregorianCalendar; //導入方法依賴的package包/類
public String getSaturday()
{
    int mondayPlus = this.getMondayPlus();
    GregorianCalendar currentDate = new GregorianCalendar();
    currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks + 6);
    Date monday = currentDate.getTime();
    DateFormat df = DateFormat.getDateInstance();
    String preMonday = df.format(monday);
    return preMonday;
}
 
開發者ID:zhuyu1022,項目名稱:amap,代碼行數:11,代碼來源:MIP_CalendarUtil2.java

示例6: handleDateTimeByHour

import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
 * <pre>
 * 描述:間隔指定小時後日期(例如:每3小時)
 * 作者:ZhangYi
 * 時間:2016年5月5日 下午4:29:07
 * 參數:(參數列表)
 * @param dateTime	指定日期
 * @param interval	間隔小時
 * @return
 * </pre>
 */
public static Date handleDateTimeByHour(Date dateTime, int interval) {
	try {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(dateTime);
		calendar.add(Calendar.HOUR, interval);
		dateTime = calendar.getTime();
	} catch (Exception e) {
		logger.error("--間隔指定小時後日期異常!", e);
	}
	return dateTime;
}
 
開發者ID:dev-share,項目名稱:css-elasticsearch,代碼行數:23,代碼來源:DateUtil.java

示例7: getWeekStartTimeMillis

import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
 * 獲取本周第一天的零點零分零秒的毫秒數
 */
public static long getWeekStartTimeMillis() {
    int mondayPlus = getMondayPlus();
    GregorianCalendar currentDate = new GregorianCalendar();
    currentDate.add(GregorianCalendar.DATE, mondayPlus);
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    return timeToTimestamp(format.format(currentDate.getTime()) + " 00:00:00");
}
 
開發者ID:z-chu,項目名稱:FriendBook,代碼行數:11,代碼來源:DateUtil.java

示例8: getCurrentWeekday

import java.util.GregorianCalendar; //導入方法依賴的package包/類
public static String getCurrentWeekday() {
    weeks = 0;
    int mondayPlus = getMondayPlus();
    GregorianCalendar currentDate = new GregorianCalendar();
    currentDate.add(GregorianCalendar.DATE, mondayPlus + 6);
    Date monday = currentDate.getTime();

    DateFormat df = DateFormat.getDateInstance();
    String preMonday = df.format(monday);
    return preMonday;
}
 
開發者ID:Datatellit,項目名稱:xlight_android_native,代碼行數:12,代碼來源:DateUtil.java

示例9: scheduleNotification

import java.util.GregorianCalendar; //導入方法依賴的package包/類
private void scheduleNotification() {
    if (reboot.equals("none")){
        return ;
    }
    GregorianCalendar rightNow = new GregorianCalendar();
    rightNow.setLenient(true);
    rightNow.setTime(new Date());

    long nowMillis =rightNow.getTimeInMillis();
    String[] rebootTime = reboot.split(":");
    rightNow.set(Calendar.HOUR_OF_DAY, Integer.parseInt(rebootTime[0]));
    rightNow.set(Calendar.MINUTE, Integer.parseInt(rebootTime[1]));
    rightNow.set(Calendar.SECOND, Integer.parseInt(rebootTime[2]));
    long  futureInMillis =rightNow.getTimeInMillis();
    if (futureInMillis < nowMillis){
        rightNow.add(Calendar.DAY_OF_MONTH, 1);
        futureInMillis =rightNow.getTimeInMillis();
    }
    final long delay =  futureInMillis - nowMillis;
    Log.d(TAG, "INTENT: set reboot at " + rightNow );
    Timer timer = new Timer();
    timer.schedule( new TimerTask(){
        @Override
        public void run() {
            rebootNow();
        }
    }, delay);
}
 
開發者ID:msillano,項目名稱:USBphpTunnel,代碼行數:29,代碼來源:SerialConsoleActivity.java

示例10: handleDateTimeByDay

import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
 * <pre>
 * 描述:間隔指定天數後日期(例如:每3天)
 * 作者:ZhangYi
 * 時間:2016年5月5日 下午4:29:07
 * 參數:(參數列表)
 * @param dateTime	指定日期
 * @param interval	間隔天數
 * @return
 * </pre>
 */
public static Date handleDateTimeByDay(Date dateTime, int interval) {
	try {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(dateTime);
		calendar.add(Calendar.DAY_OF_MONTH, interval);
		dateTime = calendar.getTime();
	} catch (Exception e) {
		logger.error("--間隔指定天數後日期異常!", e);
	}
	return dateTime;
}
 
開發者ID:dev-share,項目名稱:database-transform-tool,代碼行數:23,代碼來源:DateUtil.java

示例11: getScheduleMaxDateValue

import java.util.GregorianCalendar; //導入方法依賴的package包/類
public static Date getScheduleMaxDateValue() {
	GregorianCalendar cal = new GregorianCalendar();
	cal.add(GregorianCalendar.YEAR, 100);
	cal.set(GregorianCalendar.MONTH, 0);
	cal.set(GregorianCalendar.DATE, 1);
	return cal.getTime();
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:8,代碼來源:DateUtil.java

示例12: cleanConcertsWhenSync

import java.util.GregorianCalendar; //導入方法依賴的package包/類
@Test
public void cleanConcertsWhenSync() throws Exception {
    Concert todayConcert = new Concert.Builder("TODAY", "9001", artist2, location2)
            .date(CURRENT_TIME)
            .place("Place2001")
            .imageUrl("http://example.com/img1001.jpg")
            .url("http://example.com/events/1005")
            .build();

    GregorianCalendar past = new GregorianCalendar();
    past.setTime(CURRENT_TIME);
    past.add(Calendar.DAY_OF_MONTH, -SyncRepository.PAST_CONCERT_KEEPING_PERIOD_IN_DAYS);
    Concert pastConcert = new Concert.Builder("PAST", "9002", artist2, location2)
            .date(past.getTime())
            .place("Place2001")
            .imageUrl("http://example.com/img1001.jpg")
            .url("http://example.com/events/1005")
            .build();

    GregorianCalendar tooOldDate = new GregorianCalendar();
    tooOldDate.setTime(CURRENT_TIME);
    tooOldDate.add(Calendar.DAY_OF_MONTH,
            -(SyncRepository.PAST_CONCERT_KEEPING_PERIOD_IN_DAYS + 1));
    Concert tooOldConcert = new Concert.Builder("TOO_OLD", "9003", artist2, location2)
            .date(tooOldDate.getTime())
            .place("Place2001")
            .imageUrl("http://example.com/img1001.jpg")
            .url("http://example.com/events/1005")
            .build();

    GregorianCalendar tomorrow = new GregorianCalendar();
    tomorrow.setTime(CURRENT_TIME);
    tomorrow.add(Calendar.DAY_OF_MONTH, 1);
    Concert nonexistentConcert = new Concert.Builder("NONEXISTENT", "9004", artist2, location2)
            .date(tomorrow.getTime())
            .place("Place2001")
            .imageUrl("http://example.com/img1001.jpg")
            .url("http://example.com/events/1005")
            .build();

    // today and past (during the keeping period) concerts should always stay
    // the too old past concert should be deleted
    // the future concert should be deleted if it doesn't exist on the server
    repository.saveArtist(artist2).blockingAwait();
    repository.saveLocation(location2).blockingAwait();
    repository.saveConcerts(Arrays.asList(
            todayConcert, pastConcert, tooOldConcert, nonexistentConcert))
            .blockingAwait();

    repository.syncData(CURRENT_TIME, RELEVANCE_PERIOD_HOURS).blockingGet();

    repository.getConcerts()
            .test()
            .awaitCount(1)
            .assertNoErrors()
            .assertValue(actualConcerts -> {
                assertThat(actualConcerts)
                        .hasSize(2)
                        .containsOnly(todayConcert, pastConcert);

                return true;
            });
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:64,代碼來源:SyncRepositoryTest.java

示例13: getRandomDate

import java.util.GregorianCalendar; //導入方法依賴的package包/類
public static GregorianCalendar getRandomDate(GregorianCalendar dateMin, ValueGenerator valueGen, int days) {
	Integer dayOffset = valueGen.randomInt(0, days);
	GregorianCalendar gClone = (GregorianCalendar)dateMin.clone();
	gClone.add(GregorianCalendar.DAY_OF_MONTH, dayOffset);
	return gClone;
}
 
開發者ID:SmartDataAnalytics,項目名稱:Embeddable-BSBM,代碼行數:7,代碼來源:ParameterGenerator.java

示例14: addTypeTestData

import java.util.GregorianCalendar; //導入方法依賴的package包/類
private NodeRef addTypeTestData()
{
    addTypeTestDataModel();

    I18NUtil.setLocale(Locale.UK);

    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    MLText ml = new MLText();
    ml.addValue(Locale.ENGLISH, "Test one");
    ml.addValue(Locale.US, "Test 1");
    properties.put(ContentModel.PROP_DESCRIPTION, ml);
    properties.put(ContentModel.PROP_TITLE, ml);
    properties.put(ContentModel.PROP_NAME, "Test one");
    properties.put(ContentModel.PROP_CREATED, new Date());
    properties.put(singleTextUntokenised, "Un tokenised");
    properties.put(singleTextTokenised, "Un tokenised");
    properties.put(singleTextBoth, "Un tokenised");
    properties.put(multipleTextUntokenised, asArray("Un tokenised", "two parts"));
    properties.put(multipleTextTokenised, asArray("Un tokenised", "two parts"));
    properties.put(multipleTextBoth, asArray("Un tokenised", "two parts"));
    properties.put(singleMLTextUntokenised, makeMLText());
    properties.put(singleMLTextTokenised, makeMLText());
    properties.put(singleMLTextBoth, makeMLText());
    properties.put(multipleMLTextUntokenised, makeMLTextMVP());
    properties.put(multipleMLTextTokenised, makeMLTextMVP());
    properties.put(multipleMLTextBoth, makeMLTextMVP());
    properties.put(singleFloat, 1f);
    properties.put(multipleFloat, asArray(1f, 1.1f));
    properties.put(singleDouble, 1d);
    properties.put(multipleDouble, asArray(1d, 1.1d));
    properties.put(singleInteger, 1);
    properties.put(multipleInteger, asArray(1, 2));
    properties.put(singleLong, 1l);
    properties.put(multipleLong, asArray(1l, 2l));
    date1 = new Date();
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date1);
    cal.add(Calendar.DAY_OF_MONTH, -1);
    date0 = cal.getTime();
    cal.add(Calendar.DAY_OF_MONTH, 2);
    date2 = cal.getTime();
    properties.put(singleDate, date1);
    properties.put(multipleDate, asArray(date1, date2));
    properties.put(singleDatetime, date1);
    properties.put(multipleDatetime, asArray(date1, date2));
    properties.put(singleBoolean, true);
    properties.put(multipleBoolean, asArray(true, false));
    NodeRef c0 = nodeService.createNode(f0, ContentModel.ASSOC_CONTAINS, QName.createQName("cm", "Test One", namespaceService), extendedContent, properties).getChildRef();
    return c0;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:51,代碼來源:OpenCmisQueryTest.java

示例15: generateSAS

import java.util.GregorianCalendar; //導入方法依賴的package包/類
private static String generateSAS(CloudBlobContainer container,
    boolean readonly) throws Exception {

  // Create a container if it does not exist.
  container.createIfNotExists();

  // Create a new shared access policy.
  SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy();

  // Create a UTC Gregorian calendar value.
  GregorianCalendar calendar = new GregorianCalendar(
      TimeZone.getTimeZone("UTC"));

  // Specify the current time as the start time for the shared access
  // signature.
  //
  calendar.setTime(new Date());
  sasPolicy.setSharedAccessStartTime(calendar.getTime());

  // Use the start time delta one hour as the end time for the shared
  // access signature.
  calendar.add(Calendar.HOUR, 10);
  sasPolicy.setSharedAccessExpiryTime(calendar.getTime());

  if (readonly) {
    // Set READ permissions
    sasPolicy.setPermissions(EnumSet.of(
        SharedAccessBlobPermissions.READ,
        SharedAccessBlobPermissions.LIST));
  } else {
    // Set READ and WRITE permissions.
    //
    sasPolicy.setPermissions(EnumSet.of(
        SharedAccessBlobPermissions.READ,
        SharedAccessBlobPermissions.WRITE,
        SharedAccessBlobPermissions.LIST));
  }

  // Create the container permissions.
  BlobContainerPermissions containerPermissions = new BlobContainerPermissions();

  // Turn public access to the container off.
  containerPermissions.setPublicAccess(BlobContainerPublicAccessType.OFF);

  container.uploadPermissions(containerPermissions);

  // Create a shared access signature for the container.
  String sas = container.generateSharedAccessSignature(sasPolicy, null);
  // HACK: when the just generated SAS is used straight away, we get an
  // authorization error intermittently. Sleeping for 1.5 seconds fixes that
  // on my box.
  Thread.sleep(1500);

  // Return to caller with the shared access signature.
  return sas;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:57,代碼來源:AzureBlobStorageTestAccount.java


注:本文中的java.util.GregorianCalendar.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。