当前位置: 首页>>代码示例>>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;未经允许,请勿转载。