java.time.OffsetDateTime.minusDays()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(148)

本文整理了Java中java.time.OffsetDateTime.minusDays()方法的一些代码示例,展示了OffsetDateTime.minusDays()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.minusDays()方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名:minusDays

OffsetDateTime.minusDays介绍

[英]Returns a copy of this OffsetDateTime with the specified period in days subtracted.

This method subtracts the specified amount from the days field incrementing the month and year fields as necessary to ensure the result remains valid. The result is only invalid if the maximum/minimum year is exceeded.

For example, 2008-12-31 minus one day would result in the 2009-01-01.

This instance is immutable and unaffected by this method call.
[中]返回此OffsetDateTime的副本,并减去指定的期间(以天为单位)。
此方法从天数字段中减去指定的金额,根据需要增加月份和年份字段,以确保结果仍然有效。仅当超过最大/最小年份时,结果才无效。
例如,2008-12-31减去一天将导致2009-01-01。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: MER-C/wiki-java

  1. /**
  2. * Pipe the output to a HTML file.
  3. * @param args the command line arguments (none expected)
  4. * @throws IOException if a network error occurs
  5. */
  6. public static void main(String[] args) throws IOException
  7. {
  8. Wiki enWiki = Wiki.createInstance("en.wikipedia.org");
  9. enWiki.setMaxLag(-1);
  10. String prefix = JOptionPane.showInputDialog(null, "Enter query string");
  11. if (prefix == null)
  12. System.exit(0);
  13. Wiki.RequestHelper rh = enWiki.new RequestHelper()
  14. .withinDateRange(OffsetDateTime.now(ZoneOffset.UTC).minusDays(7), null);
  15. List<Wiki.Revision> revisions = enWiki.prefixContribs(prefix, rh);
  16. if (revisions.isEmpty())
  17. System.out.println("No contributions found.");
  18. else
  19. System.out.println(Revisions.of(enWiki).toHTML(revisions));
  20. }
  21. }

代码示例来源:origin: openmhealth/schemas

  1. @Test
  2. public void constructorShouldConstructTimeFrameWithDateTime() throws Exception {
  3. OffsetDateTime dateTime = OffsetDateTime.now().minusDays(1);
  4. TimeFrame timeFrame = new TimeFrame(dateTime);
  5. assertThat(timeFrame, notNullValue());
  6. assertThat(timeFrame.getTimeInterval(), nullValue());
  7. assertThat(timeFrame.getDateTime(), equalTo(dateTime));
  8. }

代码示例来源:origin: openmhealth/schemas

  1. @Test
  2. public void ofStartDateTimeAndEndDateTimeShouldConstructTimeInterval() throws Exception {
  3. OffsetDateTime startDateTime = OffsetDateTime.now().minusDays(1);
  4. OffsetDateTime endDateTime = OffsetDateTime.now();
  5. TimeInterval timeInterval = TimeInterval.ofStartDateTimeAndEndDateTime(startDateTime, endDateTime);
  6. assertThat(timeInterval, notNullValue());
  7. assertThat(timeInterval.getStartDateTime(), equalTo(startDateTime));
  8. assertThat(timeInterval.getEndDateTime(), equalTo(endDateTime));
  9. assertThat(timeInterval.getDuration(), nullValue());
  10. assertThat(timeInterval.getDate(), nullValue());
  11. assertThat(timeInterval.getPartOfDay(), nullValue());
  12. }

代码示例来源:origin: openmhealth/schemas

  1. @Test
  2. public void ofStartDateTimeAndDurationShouldConstructTimeInterval() throws Exception {
  3. OffsetDateTime startDateTime = OffsetDateTime.now().minusDays(1);
  4. DurationUnitValue duration = new DurationUnitValue(HOUR, ONE);
  5. TimeInterval timeInterval = TimeInterval.ofStartDateTimeAndDuration(startDateTime, duration);
  6. assertThat(timeInterval, notNullValue());
  7. assertThat(timeInterval.getStartDateTime(), equalTo(startDateTime));
  8. assertThat(timeInterval.getEndDateTime(), nullValue());
  9. assertThat(timeInterval.getDuration(), equalTo(duration));
  10. assertThat(timeInterval.getDate(), nullValue());
  11. assertThat(timeInterval.getPartOfDay(), nullValue());
  12. }

代码示例来源:origin: com.github.robozonky/robozonky-app

  1. private static void run(final TransactionalPowerTenant tenant) {
  2. final InstanceState<IncomeProcessor> state = tenant.getState(IncomeProcessor.class);
  3. final long lastSeenTransactionId = state.getValue(STATE_KEY)
  4. .map(Integer::valueOf)
  5. .orElse(-1);
  6. // transactions from overnight processing have timestamps from the midnight of previous day
  7. final LocalDate lastUpdate = state.getLastUpdated()
  8. .map(u -> u.minusDays(1).toLocalDate())
  9. .orElse(DateUtil.localNow().toLocalDate().minusWeeks(1));
  10. final Select sinceLastUpdate = new Select().greaterThanOrEquals("transaction.transactionDate", lastUpdate);
  11. final Stream<Transaction> transactions = tenant.call(z -> z.getTransactions(sinceLastUpdate));
  12. final long newLastSeenTransactionId = lastSeenTransactionId >= 0 ?
  13. processNewTransactions(tenant, transactions, lastSeenTransactionId) :
  14. processAllTransactions(transactions);
  15. state.update(m -> m.put(STATE_KEY, String.valueOf(newLastSeenTransactionId)));
  16. }

代码示例来源:origin: openmhealth/schemas

  1. @Test
  2. public void ofEndDateTimeAndDurationShouldConstructTimeInterval() throws Exception {
  3. OffsetDateTime endDateTime = OffsetDateTime.now().minusDays(1);
  4. DurationUnitValue duration = new DurationUnitValue(HOUR, ONE);
  5. TimeInterval timeInterval = TimeInterval.ofEndDateTimeAndDuration(endDateTime, duration);
  6. assertThat(timeInterval, notNullValue());
  7. assertThat(timeInterval.getStartDateTime(), nullValue());
  8. assertThat(timeInterval.getEndDateTime(), equalTo(endDateTime));
  9. assertThat(timeInterval.getDuration(), equalTo(duration));
  10. assertThat(timeInterval.getDate(), nullValue());
  11. assertThat(timeInterval.getPartOfDay(), nullValue());
  12. }

代码示例来源:origin: openmhealth/schemas

  1. @Test
  2. public void constructorShouldConstructTimeFrameWithTimeInterval() throws Exception {
  3. OffsetDateTime startDateTime = OffsetDateTime.now().minusDays(1);
  4. OffsetDateTime endDateTime = OffsetDateTime.now();
  5. TimeInterval timeInterval = TimeInterval.ofStartDateTimeAndEndDateTime(startDateTime, endDateTime);
  6. TimeFrame timeFrame = new TimeFrame(timeInterval);
  7. assertThat(timeFrame, notNullValue());
  8. assertThat(timeFrame.getTimeInterval(), equalTo(timeInterval));
  9. assertThat(timeFrame.getDateTime(), nullValue());
  10. }

代码示例来源:origin: RoboZonky/robozonky

  1. private static void run(final TransactionalPowerTenant tenant) {
  2. final InstanceState<IncomeProcessor> state = tenant.getState(IncomeProcessor.class);
  3. final long lastSeenTransactionId = state.getValue(STATE_KEY)
  4. .map(Integer::valueOf)
  5. .orElse(-1);
  6. // transactions from overnight processing have timestamps from the midnight of previous day
  7. final LocalDate lastUpdate = state.getLastUpdated()
  8. .map(u -> u.minusDays(1).toLocalDate())
  9. .orElse(DateUtil.localNow().toLocalDate().minusWeeks(1));
  10. final Select sinceLastUpdate = new Select().greaterThanOrEquals("transaction.transactionDate", lastUpdate);
  11. final Stream<Transaction> transactions = tenant.call(z -> z.getTransactions(sinceLastUpdate));
  12. final long newLastSeenTransactionId = lastSeenTransactionId >= 0 ?
  13. processNewTransactions(tenant, transactions, lastSeenTransactionId) :
  14. processAllTransactions(transactions);
  15. state.update(m -> m.put(STATE_KEY, String.valueOf(newLastSeenTransactionId)));
  16. }

代码示例来源:origin: openmhealth/schemas

  1. @Test(expectedExceptions = IllegalArgumentException.class)
  2. public void ofStartDateTimeAndEndDateTimeShouldThrowExceptionOnReversedDateTimes() throws Exception {
  3. TimeInterval.ofStartDateTimeAndEndDateTime(OffsetDateTime.now(), OffsetDateTime.now().minusDays(1));
  4. }

代码示例来源:origin: Silverpeas/Silverpeas-Core

  1. } else {
  2. final OffsetDateTime dateTime = (OffsetDateTime) startDate;
  3. occStartDate = dateTime.minusDays(1).toLocalDate();
  4. occEndDate = dateTime.plusDays(1).toLocalDate();

代码示例来源:origin: com.intuit.wasabi/wasabi-api

  1. try {
  2. LocalDate beforeExperimentDate = FilterUtil.parseUIDate(structuredFilter[1], timeZoneOffset)
  3. .minusDays(1).toLocalDate();
  4. LocalDate afterExperimentDate = FilterUtil.parseUIDate(structuredFilter[2], timeZoneOffset)
  5. .plusDays(1).toLocalDate();

代码示例来源:origin: Kaaz/DiscordBot

  1. /**
  2. * Try and figure out what type of guild it is
  3. *
  4. * @param guild the guild to check
  5. * @return what category the guild is labeled as
  6. */
  7. public GuildCheckResult checkGuild(Guild guild) {
  8. int bots = 0;
  9. int users = 0;
  10. if (MiscUtil.getCreationTime(guild.getOwner().getUser()).isBefore(OffsetDateTime.now().minusDays(BotConfig.GUILD_OWNER_MIN_ACCOUNT_AGE))) {
  11. return GuildCheckResult.OWNER_TOO_NEW;
  12. }
  13. for (Member user : guild.getMembers()) {
  14. if (user.getUser().isBot()) {
  15. bots++;
  16. }
  17. users++;
  18. }
  19. if ((double) bots / users > BotConfig.GUILD_MAX_USER_BOT_RATIO) {
  20. return GuildCheckResult.BOT_GUILD;
  21. }
  22. if (users < BotConfig.GUILD_MIN_USERS) {
  23. return GuildCheckResult.TEST_GUILD;
  24. }
  25. return GuildCheckResult.OKE;
  26. }

代码示例来源:origin: openmhealth/sample-data-generator

  1. BoundedRandomVariableTrend randomVariableTrend = new BoundedRandomVariableTrend(randomVariable, 60d, 80d);
  2. OffsetDateTime startDateTime = OffsetDateTime.now().minusDays(10);
  3. OffsetDateTime endDateTime = OffsetDateTime.now();

相关文章