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

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

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

DateTime.withDayOfMonth介绍

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

DateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of day of month changed.
[中]

代码示例

代码示例来源:origin: stackoverflow.com

DateTime dateTime = new DateTime(timestamp);
long firstDayOfMonthTimestamp = dateTime.withDayOfMonth(1).getMillis();

代码示例来源:origin: apache/incubator-pinot

case DAYS:
 _dateTimeTruncate = (dateTime) -> _outputDateTimeFormatter
   .print(dateTime.withDayOfMonth((dateTime.getDayOfMonth() / sz) * sz).dayOfMonth().roundFloorCopy());
 break;
default:

代码示例来源: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: kairosdb/kairosdb

break;
case MONTHS:
  dt = dt.withDayOfMonth(1).withMillisOfDay(0);
  break;
case WEEKS:

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

assertFunction("date_trunc('day', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));
result = result.withDayOfMonth(20);
assertFunction("date_trunc('week', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));
result = result.withDayOfMonth(1);
assertFunction("date_trunc('month', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));
assertFunction("date_trunc('day', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));
result = result.withDayOfMonth(20);
assertFunction("date_trunc('week', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));
result = result.withDayOfMonth(1);
assertFunction("date_trunc('month', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

代码示例来源:origin: me.hao0/common

/**
 * 获取本月第几天日期对象
 * @param day 1:第一天,2:第二天,...
 * @return 本月第几天日期对象
 */
public static Date dayOfMonth(Integer day){
  return new DateTime(DateTime.now().toString("yyyy-MM-dd")).withDayOfMonth(day).toDate();
}

代码示例来源:origin: ihaolin/antares

/**
 * 获取本月第几天日期对象
 * @param day 1:第一天,2:第二天,...
 * @return 本月第几天日期对象
 */
public static Date dayOfMonth(Integer day){
  return new DateTime(DateTime.now().toString("yyyy-MM-dd")).withDayOfMonth(day).toDate();
}

代码示例来源:origin: ihaolin/common

/**
 * 获取本月第几天日期对象
 * @param day 1:第一天,2:第二天,...
 * @return 本月第几天日期对象
 */
public static Date dayOfMonth(Integer day){
  return new DateTime(DateTime.now().toString("yyyy-MM-dd")).withDayOfMonth(day).toDate();
}

代码示例来源:origin: com.github.fosin/cdp-utils

/**
 * 2014-03-02 23:00:23  ===   2014-03-01 00:00:00
 *
 * @param ts ts
 * @return 结果
 */
public static <T extends Date> T firstOfMonth(T ts) {
  checkNotNull(ts);
  T cloned = (T) ts.clone();
  cloned.setTime(new DateTime(ts.getTime()).withTime(0, 0, 0, 0).withDayOfMonth(1).getMillis());
  return cloned;
}

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

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

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

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

代码示例来源:origin: com.github.fosin/cdp-utils

/**
 * 2014-03-02 23:00:23  ===   2014-03-31 23:59:59
 *
 * @param ts ts
 * @return 结果
 */
public static <T extends Date> T lastOfMonth(T ts) {
  checkNotNull(ts);
  T cloned = (T) ts.clone();
  cloned.setTime(new DateTime(ts.getTime()).withTime(0, 0, 0, 0).withDayOfMonth(1).plusMonths(1).minusSeconds(1).getMillis());
  return cloned;
}

代码示例来源:origin: stackoverflow.com

DateTimeFormatter dateParser = DateTimeFormat.forPattern("yyyy-MM-dd");        
DateTime date = dateParser.parseDateTime("2001-03-10");                        
DateTime initDate = date;                                                      
date = date.withDayOfMonth(13); //reset to the 13 of the current month          
if (date.compareTo(initDate) == -1) //add a month if the start date was after 13 
  date=date.plusMonths(1);                                                   
while (date.getYear() == initDate.getYear()) {                                 
  date = date.plusMonths(1);                                                 
  if (date.getDayOfWeek() == DateTimeConstants.FRIDAY)                       
    System.out.println("date = " + date);                                  
}

代码示例来源:origin: com.yahoo.maha/maha-par-request

public static int getPreviousMonthStartHourId(int currentHourId) {
  return getHours(
    new DateTime((long) currentHourId * 3600 * 1000, TimeUtil.EASTERN).minusMonths(1).withDayOfMonth(1)
      .withTimeAtStartOfDay());
}

代码示例来源:origin: com.yahoo.maha/maha-par-request-2

public static int getPreviousMonthStartHourId(int currentHourId) {
  return getHours(
    new DateTime((long) currentHourId * 3600 * 1000, TimeUtil.EASTERN).minusMonths(1).withDayOfMonth(1)
      .withTimeAtStartOfDay());
}

代码示例来源:origin: qcadoo/mes

public void onBeforeRender(final ViewDefinitionState view) {

    if (view.isViewAfterRedirect()) {
      FieldComponent dateToField = (FieldComponent) view.getComponentByReference("toDate");
      dateToField.setFieldValue(DateUtils.toDateTimeString(new Date()));

      FieldComponent fromDateField = (FieldComponent) view.getComponentByReference("fromDate");
      fromDateField.setFieldValue(DateUtils.toDateTimeString(new DateTime().withDayOfMonth(1).toDate()));

      dateToField.requestComponentUpdateState();
      fromDateField.requestComponentUpdateState();
    }

  }
}

代码示例来源: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.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.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;
}

相关文章

DateTime类方法