org.joda.time.DateTime.withMonthOfYear()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(350)

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

DateTime.withMonthOfYear介绍

[英]Returns a copy of this datetime with the month of year field updated.

DateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of month of year changed.
[中]返回此datetime的副本,其中“月份”字段已更新。
DateTime是不可变的,因此没有set方法。相反,此方法返回一个新实例,其值为month of year changed。

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

/**
 * Default expiration date construction.
 * Some Payment Gateways may require a different format. Override if necessary or set the property
 * "gateway.config.global.expDateFormat" with a format string to provide the correct format for the configured gateway.
 * @param expMonth
 * @param expYear
 * @return
 */
protected String constructExpirationDate(Integer expMonth, Integer expYear) {
  SimpleDateFormat sdf = new SimpleDateFormat(getGatewayExpirationDateFormat());
  DateTime exp = new DateTime()
      .withYear(expYear)
      .withMonthOfYear(expMonth);
  return sdf.format(exp.toDate());
}

代码示例来源:origin: prestodb/presto

@Test
public void testTruncateDate()
{
  DateTime result = DATE;
  assertFunction("date_trunc('day', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withDayOfMonth(20);
  assertFunction("date_trunc('week', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withDayOfMonth(1);
  assertFunction("date_trunc('month', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withMonthOfYear(7);
  assertFunction("date_trunc('quarter', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withMonthOfYear(1);
  assertFunction("date_trunc('year', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
}

代码示例来源:origin: prestodb/presto

assertFunction("date_trunc('month', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));
result = result.withMonthOfYear(7);
assertFunction("date_trunc('quarter', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));
result = result.withMonthOfYear(1);
assertFunction("date_trunc('year', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));
assertFunction("date_trunc('month', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));
result = result.withMonthOfYear(7);
assertFunction("date_trunc('quarter', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));
result = result.withMonthOfYear(1);
assertFunction("date_trunc('year', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

代码示例来源:origin: urbanairship/datacube

public static DateTime yearFloor(DateTime dt) {
  return monthFloor(dt).withMonthOfYear(1);
}

代码示例来源:origin: fi.vm.sade.tarjonta/tarjonta-shared

public static Date getDateFromYearAndKausi(Integer year, String kausi) {
  Integer month = 1; // kevät by default
  if (kausi != null && SYKSY_URI.split("#")[0].equals(kausi.split("#")[0])) {
    month = 8;
  }
  return new DateTime().withYear(year).withMonthOfYear(month).withDayOfMonth(1).toDate();
}

代码示例来源:origin: grahamar/cron-parser

@Override
protected String getSingleItemDescription(String expression) {
  return new DateTime().withDayOfMonth(1).withMonthOfYear(Integer.parseInt(expression)).
      toString("MMMM", I18nMessages.getCurrentLocale());
}

代码示例来源:origin: io.virtdata/virtdata-lib-basics

@Override
  public long applyAsLong(long operand) {
    return new DateTime(operand,tz).withTimeAtStartOfDay().withDayOfMonth(1).withMonthOfYear(1).getMillis();
  }
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

@Override
  public long applyAsLong(long operand) {
    return new DateTime(operand,tz).withTimeAtStartOfDay().withDayOfMonth(1).withMonthOfYear(1).getMillis();
  }
}

代码示例来源:origin: bingoohuang/quartz-glass

@Override
protected String getSingleItemDescription(String expression) {
  if (!NumberUtils.isNumber(expression)) {
    return DateTimeFormat.forPattern("MMM").withLocale(Locale.ENGLISH).parseDateTime(expression).toString("MMMM", Locale.ENGLISH);
  }
  return new DateTime().withDayOfMonth(1).withMonthOfYear(Integer.parseInt(expression)).toString("MMMM", Locale.ENGLISH);
}

代码示例来源:origin: de.ck35.metricstore/metricstore-fs

public static DateTime atEndOfYear(DateTime current) {
  return current.withMonthOfYear(1).withDayOfMonth(1).plusYears(1).minusDays(1);
}
public static DateTime atEndOfMonth(DateTime current) {

代码示例来源:origin: Appendium/objectlabkit

public static DateTime getDateTime(final double date, final boolean use1904windowing) {
    final Calendar c = ExcelDateUtil.getJavaCalendar(date, use1904windowing);

    if (c == null) {
      return null;
    }

    return new DateTime().withYear(c.get(Calendar.YEAR)).withMonthOfYear(c.get(Calendar.MONTH) + 1).withDayOfMonth(c.get(Calendar.DAY_OF_MONTH))
        .withMillisOfDay(0);
  }
}

代码示例来源:origin: net.objectlab.kit/datecalc-joda

public static DateTime getDateTime(final double date, final boolean use1904windowing) {
    final Calendar c = ExcelDateUtil.getJavaCalendar(date, use1904windowing);

    if (c == null) {
      return null;
    }

    return new DateTime().withYear(c.get(Calendar.YEAR)).withMonthOfYear(c.get(Calendar.MONTH) + 1).withDayOfMonth(c.get(Calendar.DAY_OF_MONTH))
        .withMillisOfDay(0);
  }
}

代码示例来源:origin: org.richfaces/richfaces-page-fragments

public DateTime getDate() {
  return new DateTime().withMonthOfYear(getSelectedMonthNumber()).withYear(getSelectedYearNumber());
}

代码示例来源:origin: org.springframework.analytics/spring-analytics

private long[] getMinCountsForHour(String name, int year, int month, int day, int hour) {
  DateTime dt = new DateTime().withYear(year).withMonthOfYear(month).withDayOfMonth(day).withHourOfDay(hour);
  AggregateKeyGenerator akg = new AggregateKeyGenerator(
      AGGREGATE_COUNTER_KEY_PREFIX, name, dt);
  return convertToArray(getEntries(akg.getHourKey()), 60, false);
}

代码示例来源:origin: org.springframework.cloud.stream.app/app-starters-common-analytics

private long[] getMinCountsForHour(String name, int year, int month, int day, int hour) {
  DateTime dt = new DateTime().withYear(year).withMonthOfYear(month).withDayOfMonth(day).withHourOfDay(hour);
  AggregateKeyGenerator akg = new AggregateKeyGenerator(REPO_PREFIX, name, dt);
  return convertToArray(getEntries(akg.getHourKey()), 60, false);
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Override
public IntervalWindow assignWindow(Instant timestamp) {
 DateTime datetime = new DateTime(timestamp, timeZone);
 DateTime offsetStart = startDate.withMonthOfYear(monthOfYear).withDayOfMonth(dayOfMonth);
 int yearOffset = Years.yearsBetween(offsetStart, datetime).getYears() / number * number;
 DateTime begin = offsetStart.plusYears(yearOffset);
 DateTime end = begin.plusYears(number);
 return new IntervalWindow(begin.toInstant(), end.toInstant());
}

代码示例来源:origin: metatron-app/metatron-discovery

public DateTime atStartDateTime(DateTime dateTime) {
 switch (this) {
  case YEAR:
   return dateTime.withTimeAtStartOfDay().withMonthOfYear(1);
  case MONTH:
   return dateTime.withTimeAtStartOfDay().withDayOfMonth(1);
  case WEEK:
   return dateTime.withTimeAtStartOfDay().withDayOfWeek(1);
  case DAY:
   return dateTime.withTimeAtStartOfDay();
 }
 return dateTime;
}

代码示例来源:origin: io.prestosql/presto-main

@Test
public void testTruncateDate()
{
  DateTime result = DATE;
  assertFunction("date_trunc('day', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withDayOfMonth(20);
  assertFunction("date_trunc('week', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withDayOfMonth(1);
  assertFunction("date_trunc('month', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withMonthOfYear(7);
  assertFunction("date_trunc('quarter', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withMonthOfYear(1);
  assertFunction("date_trunc('year', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
}

代码示例来源:origin: prestosql/presto

@Test
public void testTruncateDate()
{
  DateTime result = DATE;
  assertFunction("date_trunc('day', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withDayOfMonth(20);
  assertFunction("date_trunc('week', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withDayOfMonth(1);
  assertFunction("date_trunc('month', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withMonthOfYear(7);
  assertFunction("date_trunc('quarter', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withMonthOfYear(1);
  assertFunction("date_trunc('year', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

@Test
public void testTruncateDate()
{
  DateTime result = DATE;
  assertFunction("date_trunc('day', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withDayOfMonth(20);
  assertFunction("date_trunc('week', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withDayOfMonth(1);
  assertFunction("date_trunc('month', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withMonthOfYear(7);
  assertFunction("date_trunc('quarter', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
  result = result.withMonthOfYear(1);
  assertFunction("date_trunc('year', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
}

相关文章

DateTime类方法