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


Java DateTime.plusDays方法代码示例

本文整理汇总了Java中org.joda.time.DateTime.plusDays方法的典型用法代码示例。如果您正苦于以下问题:Java DateTime.plusDays方法的具体用法?Java DateTime.plusDays怎么用?Java DateTime.plusDays使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.joda.time.DateTime的用法示例。


在下文中一共展示了DateTime.plusDays方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDateOfCurrentMonday

import org.joda.time.DateTime; //导入方法依赖的package包/类
private String getDateOfCurrentMonday() {
    DateTime currentDate = new DateTime();

    if (currentDate.getDayOfWeek() == DateTimeConstants.SATURDAY) {
        currentDate = currentDate.plusDays(2);
    } else if (currentDate.getDayOfWeek() == DateTimeConstants.SUNDAY) {
        currentDate = currentDate.plusDays(1);
    } else {
        currentDate = currentDate.withDayOfWeek(DateTimeConstants.MONDAY);
    }
    return currentDate.toString(DATE_PATTERN);
}
 
开发者ID:wulkanowy,项目名称:wulkanowy,代码行数:13,代码来源:TimetableFragment.java

示例2: getDateBetweenDates

import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
 * 获取两个日期之间的所有日期
 * 忽略日期前后顺序,会自动判断两个日期前后顺序
 *
 *  例如:2016-9-30 23:59:59 至 2019-10-01 00:00:01 , yyyy-MM-dd
 * 返回值为 ["2016-9-30"]
 *
 * @param date1
 * @param date2
 * @return
 */
public static List<Date> getDateBetweenDates(@NotNull Date date1, @NotNull Date date2) {
    Objects.requireNonNull(date1, "startDate must not null");
    Objects.requireNonNull(date2, "endDate must not null");
    Date startDate = date1;
    Date endDate = date2;
    //调整顺序
    if (date1.after(date2)) {
        startDate = date2;
        endDate = date1;
    }
    List<Date> dates = new ArrayList<>();
    long startmilliseconds = getFirstMilliSecondOfDate(startDate);
    long endmilliseconds = getLastMilliSecondOfDate(endDate);
    DateTime dateTime = new DateTime(startDate);
    while (startmilliseconds<endmilliseconds) {
        dates.add(dateTime.toDate());
        dateTime = dateTime.plusDays(1);
        startmilliseconds = getFirstMilliSecondOfDate(dateTime.toDate());
    }
    return dates;
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:33,代码来源:DateCalculator.java

示例3: getDateStrBetweenDates

import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
 * 获取两个日期之间的所有日期字符串,按照指定日期格式化
 * 忽略日期前后顺序,会自动判断两个日期前后顺序
 * 使用的是 DateTime.isBefore() 比较时间戳
 * 例如:2016-9-30 23:59:59 至 2019-10-01 00:00:01 , yyyy-MM-dd
 * 返回值为 ["2016-9-30","2019-10-01"]
 * @param date1
 * @param date2
 * @param pattern
 * @return
 */
public static List<String> getDateStrBetweenDates(@NotNull Date date1, @NotNull Date date2, @NotNull String pattern) {
    Objects.requireNonNull(date1, "startDate must not null");
    Objects.requireNonNull(date2, "endDate must not null");
    Objects.requireNonNull(pattern, "pattern must not null");
    Date startDate = date1;
    Date endDate = date2;
    //调整顺序
    if (date1.after(date2)) {
        startDate = date2;
        endDate = date1;
    }
    List<String> dates = new ArrayList<>();
    long startmilliseconds = getFirstMilliSecondOfDate(startDate);
    long endmilliseconds = getLastMilliSecondOfDate(endDate);
    DateTime dateTime = new DateTime(startDate);
    while (startmilliseconds<endmilliseconds) {
        dates.add(DateFormatter.format(dateTime.getMillis(), pattern));
        dateTime = dateTime.plusDays(1);
        startmilliseconds = getFirstMilliSecondOfDate(dateTime.toDate());
    }
    return dates;
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:34,代码来源:DateCalculator.java

示例4: onCreate

import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_journal);
    ButterKnife.bind(this);

    currentTrip = new Trip();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    DateTime today = DateTime.now();
    dpDialog = DatePickerDialog.newInstance(this,
            today.getYear(), today.getMonthOfYear() - 1, today.getDayOfMonth());


    startDateView.setText(formatted(today));
    endDateView.setText(formatted(today.plusDays(1)));
    startDate = today;
    endDate = today.plusDays(1);
}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:22,代码来源:NewJournalActivity.java

示例5: testGetPublishIdToSnapshotFrom

import org.joda.time.DateTime; //导入方法依赖的package包/类
@Test
public void testGetPublishIdToSnapshotFrom() throws Exception {
    String excludeInstanceId = "exclude-352768";
    List<String> instanceIds = new ArrayList<>();
    instanceIds.add(excludeInstanceId);
    instanceIds.add(instanceId);
    instanceIds.add("extra-89351");

    Date dt = new Date();

    DateTime originalDateTime = new DateTime(dt);
    Date originalDate = originalDateTime.toDate();
    DateTime originalPlusOneDateTime = originalDateTime.plusDays(1);
    Date originalPlusOneDate = originalPlusOneDateTime.toDate();

    when(awsHelperService.getInstanceIdsForAutoScalingGroup(
        envValues.getAutoScaleGroupNameForPublish())).thenReturn(instanceIds);

    Map<String, String> instanceTags1 = new HashMap<>();
    instanceTags1.put(InstanceTags.SNAPSHOT_ID.getTagName(), "");

    when(awsHelperService.getTags(anyString())).thenReturn(instanceTags1);

    when(awsHelperService.getLaunchTime(instanceId)).thenReturn(originalDate);
    when(awsHelperService.getLaunchTime("extra-89351")).thenReturn(originalPlusOneDate);

    when(httpUtil.isHttpGetResponseOk(anyString())).thenReturn(true);
    
    String resultInstanceId = aemHelperService.getPublishIdToSnapshotFrom(excludeInstanceId);
    
    assertThat(resultInstanceId, equalTo(instanceId));
}
 
开发者ID:shinesolutions,项目名称:aem-orchestrator,代码行数:33,代码来源:AemInstanceHelperServiceTest.java

示例6: getEvictionDate

import org.joda.time.DateTime; //导入方法依赖的package包/类
@PreAuthorize ("isAuthenticated()")
@Transactional (readOnly=true, propagation=Propagation.REQUIRED)
public Date getEvictionDate(Product product)
{
   Eviction e = getEviction();
   if (e.getStrategy() == EvictionStrategy.NONE)
   {
      return null;
   }

   DateTime dt = new DateTime(product.getCreated());
   DateTime res = dt.plusDays(e.getKeepPeriod());
   return res.toDate();
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:15,代码来源:EvictionService.java

示例7: getExpanded

import org.joda.time.DateTime; //导入方法依赖的package包/类
private boolean getExpanded(String dayDate) {
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(DATE_PATTERN);
    DateTime dayTime = dateTimeFormatter.parseDateTime(dayDate);

    DateTime currentDate = new DateTime();

    if (currentDate.getDayOfWeek() == DateTimeConstants.SATURDAY) {
        currentDate = currentDate.plusDays(2);
    } else if (currentDate.getDayOfWeek() == DateTimeConstants.SUNDAY) {
        currentDate = currentDate.plusDays(1);
    }

    return DateTimeComparator.getDateOnlyInstance().compare(currentDate, dayTime) == 0;
}
 
开发者ID:wulkanowy,项目名称:wulkanowy,代码行数:15,代码来源:TimetableFragmentTab.java

示例8: execute

import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public void execute(MessageReceivedEvent event, String[] args) {
    DateTime current = new DateTime(DateTimeZone.forID("America/Montreal"));
    if (current.getDayOfWeek() == DateTimeConstants.TUESDAY) {
        current = current.plusDays(1);
    }
    while (current.getDayOfWeek() != DateTimeConstants.TUESDAY) {
        current = current.plusDays(1);
    }
    int weeks = Weeks.weeksBetween(Utils.startDateMythicPlus, current).getWeeks();
    String[] weekAffixes = Utils.mythicPlusAffixes[weeks % 12];
    event.getChannel().sendMessage(Utils.createMythicEmbed(bot, event.getGuild(), weekAffixes).build()).queue();
}
 
开发者ID:greatman,项目名称:legendarybot,代码行数:14,代码来源:NextAffixCommand.java

示例9: getDateTime

import org.joda.time.DateTime; //导入方法依赖的package包/类
private DateTime getDateTime(String inputDate) {
    DateTime todayDate = new DateTime(DateTimeZone.UTC);
    int increaseDays = 0;
    DateTime newDate;

    try {
        String increaseString = "+0";
        //String increaseString = inputDate.substring(TODAY_PLACEHOLDER.length(), inputDate.length() - 1); // // example: increaseString = "+1"

        String patternForToday = "(\\+[0-9]*|\\-[0-9]*)"; //example: increaseString = "+1"
        Pattern todayPattern = Pattern.compile(patternForToday);
        Matcher todayMatcher = todayPattern.matcher(inputDate);
        if (todayMatcher.find()) {
           // there is an increment
            increaseString = todayMatcher.group(0);
            logger.debug("{} DateHandler - getDateTime --> there is an increase date = '{}'", testDetails, increaseString);
        }
        increaseDays = Integer.parseInt(increaseString.substring(1));
        if (increaseString.startsWith("+")) {
            newDate = todayDate.plusDays(increaseDays);
        } else if (increaseString.startsWith("-")) {
            newDate = todayDate.plusDays(increaseDays * (-1));
        } else {
            newDate = todayDate;
        }
    } catch (Exception oEx) {
        logger.error("{} DateHandler - getDateTime >> exception: '{}'", testDetails, oEx.getLocalizedMessage());
        newDate = todayDate;
    }
    return newDate;
}
 
开发者ID:HotelsDotCom,项目名称:heat,代码行数:32,代码来源:DateHandler.java

示例10: 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

示例11: replaceOneString

import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public String replaceOneString(String body, Request request) {
    Matcher dateTimeMatcher = DATETIME.matcher(body);
    dateTimeMatcher.find();

    String match = dateTimeMatcher.group();
    Map<String, String> query = getQueryFromUri(match);
    DateTime time = new DateTime();
    if(query.containsKey(OFFSET_PARAMETER)) {
        time = time.plusDays(Integer.parseInt(query.get(OFFSET_PARAMETER)));
    }
    String timeString = time.toString();
    body = dateTimeMatcher.replaceFirst(timeString);
    return body;
}
 
开发者ID:politedog,项目名称:mock-interceptor,代码行数:16,代码来源:AbstractMockedApiInterceptor.java

示例12: setCacheScanSoftIfMiss

import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public void setCacheScanSoftIfMiss(HttpServletResponse resp) {
    DateTime dt = new DateTime();

    dt = dt.millisOfDay().setCopy(0);
    resp.setHeader("Last-Modified", toGMT(dt));
    dt = dt.plusDays(expiresDaysForScansoftIfMiss);
    resp.setHeader("Expires", toGMT(dt));
    resp.setHeader("Cache-Control", maxAgeIfMiss);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:11,代码来源:CDNCacheImpl.java

示例13: readAgenda

import org.joda.time.DateTime; //导入方法依赖的package包/类
@Test
public void readAgenda() throws IOException {
  //given
  final DateTime from = DateTime.now().minusDays(1);
  final DateTime to = from.plusDays(2);

  //when
  List<String> result = toTest.readAgenda(from, to);

  //then
  assertTrue(result.isEmpty());

  ArgumentCaptor<CommandLine> cmdCap = ArgumentCaptor.forClass(CommandLine.class);
  verify(toTest, times(1)).doExecute(cmdCap.capture(), any());

  assertEquals("calendar-cli.py", cmdCap.getValue().getExecutable());
  assertEquals(15, cmdCap.getValue().getArguments().length);
  assertEquals("--caldav-url", cmdCap.getValue().getArguments()[0]);
  assertEquals(CALDAV_URL, cmdCap.getValue().getArguments()[1]);
  assertEquals("--caldav-user", cmdCap.getValue().getArguments()[2]);
  assertEquals(CALDAV_USER, cmdCap.getValue().getArguments()[3]);
  assertEquals("--caldav-pass", cmdCap.getValue().getArguments()[4]);
  assertEquals(CALDAV_PASSWORD, cmdCap.getValue().getArguments()[5]);
  assertEquals("--calendar-url", cmdCap.getValue().getArguments()[6]);
  assertEquals(CALENDAR_URL, cmdCap.getValue().getArguments()[7]);
  assertEquals("--icalendar", cmdCap.getValue().getArguments()[8]);
  assertEquals("calendar", cmdCap.getValue().getArguments()[9]);
  assertEquals("agenda", cmdCap.getValue().getArguments()[10]);
  assertEquals("--from-time", cmdCap.getValue().getArguments()[11]);
  assertEquals(from.toString(), cmdCap.getValue().getArguments()[12]);
  assertEquals("--to-time", cmdCap.getValue().getArguments()[13]);
  assertEquals(to.toString(), cmdCap.getValue().getArguments()[14]);
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:34,代码来源:CalendarCLIAdapterTest.java

示例14: DummyJournal

import org.joda.time.DateTime; //导入方法依赖的package包/类
public DummyJournal(String name, String location, DateTime startDate) {
    this.name = name;
    this.location = location;
    this.startDate = startDate;
    this.endDate = startDate.plusDays(7);
}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:7,代码来源:DummyContent.java

示例15: onCreate

import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_journal);
    ButterKnife.bind(this);

    Intent data = getIntent();
    if (data.hasExtra("TRIP")) {
        toolbar.setTitle("Edit Journal");
        Parcelable par = data.getParcelableExtra("TRIP");
        currentTrip = Parcels.unwrap(par);
        FirebaseAuth auth = FirebaseAuth.getInstance();
        String uid = auth.getCurrentUser().getUid();
        DatabaseReference ref = FirebaseDatabase.getInstance()
                .getReference(uid).child(currentTrip.getKey())
                .child("entries");
        photoFrag = PhotoFragment.newInstance(ref.toString());
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, photoFrag)
                .commit();
        jname.setText(currentTrip.getName());
        location.setText(currentTrip.getLocation());
        startDateView.setText(formatted(DateTime.parse(currentTrip
                .getStartDate())));
        endDateView.setText(formatted(DateTime.parse(currentTrip.getEndDate())));
        startDate = DateTime.parse(currentTrip.getStartDate());
        endDate = DateTime.parse(currentTrip.getEndDate());
    } else {
        toolbar.setTitle("New Journal");
        currentTrip = new Trip();
        DateTime today = DateTime.now();
        startDateView.setText(formatted(today));
        endDateView.setText(formatted(today.plusDays(1)));
        startDate = today;
        endDate = today.plusDays(1);
    }
    dpDialog = DatePickerDialog.newInstance(this,
            startDate.getYear(), startDate.getMonthOfYear() - 1, startDate
                    .getDayOfMonth());

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:45,代码来源:TripEditorActivity.java


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