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

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

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

DateTime.getYear介绍

暂无

代码示例

代码示例来源:origin: Graylog2/graylog2-server

private static Map<String, Object> ingestTimeFields(DateTime ingestTime) {
  return ImmutableMap.<String, Object>builder()
      .put("ingest_time", ingestTime.toString())
      .put("ingest_time_epoch", ingestTime.getMillis())
      .put("ingest_time_second", ingestTime.getSecondOfMinute())
      .put("ingest_time_minute", ingestTime.getMinuteOfHour())
      .put("ingest_time_hour", ingestTime.getHourOfDay())
      .put("ingest_time_day", ingestTime.getDayOfMonth())
      .put("ingest_time_month", ingestTime.getMonthOfYear())
      .put("ingest_time_year", ingestTime.getYear())
      .build();
}

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

startTime = startTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(), currentTime.getDayOfMonth());
endTime = endTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(), currentTime.getDayOfMonth());

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

@Override
 public GenericRecord partitionForRecord(GenericRecord record) {
  GenericRecord partition = new GenericData.Record(_partitionSchema);
  String dateString = record.get(_dateColumn).toString();
  DateTime date = _dateFormatter.parseDateTime(dateString);

  if (_withPrefix) {
   if (_withColumnNames) {
    partition.put(PARTITION_COLUMN_PREFIX, PARTITION_COLUMN_PREFIX + "=" + _prefix);
   } else {
    partition.put(PARTITION_COLUMN_PREFIX, _prefix);
   }
  }

  if (_withColumnNames) {
   partition.put(PARTITION_COLUMN_YEAR, PARTITION_COLUMN_YEAR + "=" + date.getYear());
   partition.put(PARTITION_COLUMN_MONTH, PARTITION_COLUMN_MONTH + "=" + date.getMonthOfYear());
   partition.put(PARTITION_COLUMN_DAY, PARTITION_COLUMN_DAY + "=" + date.getDayOfMonth());
  } else {
   partition.put(PARTITION_COLUMN_YEAR, date.getYear());
   partition.put(PARTITION_COLUMN_MONTH, date.getMonthOfYear());
   partition.put(PARTITION_COLUMN_DAY, date.getDayOfMonth());
  }

  return partition;
 }
}

代码示例来源:origin: joda-time/joda-time

/**
 * Returns a copy of this datetime with the specified time, retaining the date fields.
 * <p>
 * If the time is already the time passed in, then <code>this</code> is returned.
 * <p>
 * To set a single field use the properties, for example:
 * <pre>
 * DateTime set = dt.hourOfDay().setCopy(6);
 * </pre>
 * <p>
 * If the new time is invalid due to the time-zone, the time will be adjusted.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param hourOfDay  the hour of the day
 * @param minuteOfHour  the minute of the hour
 * @param secondOfMinute  the second of the minute
 * @param millisOfSecond  the millisecond of the second
 * @return a copy of this datetime with a different time
 * @throws IllegalArgumentException if any value if invalid
 */
public DateTime withTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) {
  Chronology chrono = getChronology();
  long localInstant = chrono.withUTC().getDateTimeMillis(
    getYear(), getMonthOfYear(), getDayOfMonth(), hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
  return withMillis(chrono.getZone().convertLocalToUTC(localInstant, false, getMillis()));
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * Returns a copy of this datetime with the specified time, retaining the date fields.
 * <p>
 * If the time is already the time passed in, then <code>this</code> is returned.
 * <p>
 * To set a single field use the properties, for example:
 * <pre>
 * DateTime set = dt.hourOfDay().setCopy(6);
 * </pre>
 * <p>
 * If the new time is invalid due to the time-zone, the time will be adjusted.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param hourOfDay  the hour of the day
 * @param minuteOfHour  the minute of the hour
 * @param secondOfMinute  the second of the minute
 * @param millisOfSecond  the millisecond of the second
 * @return a copy of this datetime with a different time
 * @throws IllegalArgumentException if any value if invalid
 */
public DateTime withTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) {
  Chronology chrono = getChronology();
  long localInstant = chrono.withUTC().getDateTimeMillis(
    getYear(), getMonthOfYear(), getDayOfMonth(), hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
  return withMillis(chrono.getZone().convertLocalToUTC(localInstant, false, getMillis()));
}

代码示例来源:origin: apache/drill

@Test
public void testYearAndMonthDayFormat() {
 String day = "01";
 String month = "08";
 int year = 2011;
 DateTime date = parseDateFromPostgres(year + "-" + month + day, "YYYY-MMDD");
 Assert.assertTrue(date.getDayOfMonth() == Integer.parseInt(day) &&
           date.getMonthOfYear() == Integer.parseInt(month) &&
           date.getYear() == year);
}

代码示例来源:origin: apache/drill

@Test
public void testDateDayMonthYearFormat() {
 String day = "01";
 String month = "08";
 int year = 2011;
 DateTime date = parseDateFromPostgres(year + "-" + month + "-" + day, "YYYY-MM-DD");
 Assert.assertTrue(date.getDayOfMonth() == Integer.parseInt(day) &&
           date.getMonthOfYear() == Integer.parseInt(month) &&
           date.getYear() == year);
}

代码示例来源:origin: apache/drill

@Test
public void testYearMonthDayFormat() {
 String day = "01";
 String month = "08";
 int year = 2011;
 DateTime date = parseDateFromPostgres(year + "" + month + day, "YYYYMMDD");
 Assert.assertTrue(date.getDayOfMonth() == Integer.parseInt(day) &&
           date.getMonthOfYear() == Integer.parseInt(month) &&
           date.getYear() == year);
}

代码示例来源:origin: apache/drill

@Test
public void testDateYearMonthDayFormat() {
 String day = "05";
 String month = "Dec";
 int year = 2000;
 DateTime date = parseDateFromPostgres(day + " " + month + " " + year, "DD Mon YYYY");
 Assert.assertTrue(date.getDayOfMonth() == Integer.parseInt(day) &&
           date.getMonthOfYear() == 12 &&
           date.getYear() == year);
}

代码示例来源:origin: apache/drill

@Test
public void testYearMonthNameDayFormat() {
 String day = "30";
 String month = "Nov";
 int year = 2000;
 DateTime date = parseDateFromPostgres(year + "" + month + day, "YYYYMonDD");
 Assert.assertTrue(date.getDayOfMonth() == Integer.parseInt(day) &&
           date.getMonthOfYear() == 11 &&
           date.getYear() == year);
}

代码示例来源:origin: apache/drill

@Test
public void testDateMonthDayYearFormat() {
 int day = 1;
 int month = 8;
 int year = 2011;
 DateTime date = parseDateFromPostgres(month + "/" + day + "/" + year, "MM/DD/YYYY");
 Assert.assertTrue(date.getDayOfMonth() == day &&
           date.getMonthOfYear() == month &&
           date.getYear() == year);
}

代码示例来源:origin: apache/drill

@Test
public void testDateDayOfYearYearFormat() {
 String day = "01";
 int year = 2011;
 DateTime date = parseDateFromPostgres(day + "/" + year, "ddd/YYYY");
 Assert.assertTrue(date.getDayOfMonth() == 1 &&
           date.getMonthOfYear() == 1 &&
           date.getYear() == year);
}

代码示例来源:origin: apache/drill

@Test
public void testDateYearMonthNameFormat() {
 String month = "JUN";
 int year = 2000;
 DateTime date = parseDateFromPostgres(year + " " + month, "YYYY MON");
 Assert.assertTrue(date.getMonthOfYear() == 6 && date.getYear() == year);
}

代码示例来源:origin: apache/drill

@Test
public void testDateTimeHoursMinutesSecondsFormat() {
 String day = "24";
 String month = "June";
 int year = 2010;
 int hours = 10;
 int minutes = 12;
 DateTime date = parseDateFromPostgres(year + "" + day + month + hours + ":" + minutes + "am", "YYYYDDFMMonthHH12:MIam");
 Assert.assertTrue(date.getDayOfMonth() == Integer.parseInt(day) &&
           date.getMonthOfYear() == 6 &&
           date.getYear() == year &&
           date.getHourOfDay() == hours &&
           date.getMinuteOfHour() == minutes);
}

代码示例来源:origin: apache/hive

return Date.of(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth());
default:
 throw new BackendException("Unexpected HCat type " + type + " for value " + pigObj

代码示例来源:origin: linkedin/camus

public DateTime getMidnight() {
 DateTime time = new DateTime(zone);
 return new DateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(), 0, 0, 0, 0, zone);
}

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

assertFunction("extract(doy FROM " + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getDayOfYear());
assertFunction("extract(week FROM " + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getWeekOfWeekyear());
assertFunction("extract(month FROM " + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getMonthOfYear());
assertFunction("extract(quarter FROM " + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getMonthOfYear() / 4 + 1);
assertFunction("extract(year FROM " + TIMESTAMP_LITERAL + ")", BIGINT, (long) TIMESTAMP.getYear());
assertFunction("extract(doy FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getDayOfYear());
assertFunction("extract(week FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getWeekOfWeekyear());
assertFunction("extract(month FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getMonthOfYear());
assertFunction("extract(quarter FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getMonthOfYear() / 4 + 1);
assertFunction("extract(year FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) WEIRD_TIMESTAMP.getYear());
assertFunction("extract(timezone_minute FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, 9L);
assertFunction("extract(timezone_hour FROM " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, 7L);

代码示例来源:origin: linkedin/camus

public DateTime getCurrentHour() {
  DateTime time = new DateTime(zone);
  return new DateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(), time.getHourOfDay(), 0, 0, 0, zone);
 }
}

代码示例来源:origin: xiaojianglaile/Calendar

private int[] getYearAndMonth(int position) {
  int date[] = new int[2];
  DateTime time = new DateTime();
  time = time.plusMonths(position - mMonthCount / 2);
  date[0] = time.getYear();
  date[1] = time.getMonthOfYear() - 1;
  return date;
}

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

new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), now.getHourOfDay(), 30, 0, TZ);

相关文章

DateTime类方法